Skip to content

Conversation

glbrntt
Copy link
Contributor

@glbrntt glbrntt commented Feb 19, 2024

Motivation:

The AsyncDNSResolver currently throws an error when there are no records associated with a name. However, most query responses are arrays or contain arrays. As such it's unclear to callers whether they should be catching an error of a particular type or checking for the presence of values some combination of the two.

Modifications:

  • Modify the DNSResolver API to return nil where only a single value is expected (e.g. CNAME).
  • Update documentation on DNSResolver to clarify the expected return values when no values are resolved.
  • Update the c-ares backend to check for no data when parsing and return empty responses
  • Update the DNSSD backend to pass in nil data to the parser when the status is timeout
  • Remove the noData error code as it shouldn't be reachable anymore

Result:

Queries with no response either return empty or nil

@glbrntt glbrntt requested a review from yim-lee February 19, 2024 16:51
/// - name: The name to resolve.
///
/// - Returns: ``PTRRecord`` for the given name.
/// - Returns: ``PTRRecord`` for the given name, `nil` if no record was found.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess in case of PTRRecord, names is empty if no records found?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, good catch, the doc is wrong here.

glbrntt added 2 commits March 4, 2024 16:05
Motivation:

The AsyncDNSResolver currently throws an error when there are no records
associated with a name. However, most query responses are arrays or
contain arrays. As such it's unclear to callers whether they should be
catching an error of a particular type or checking for the presence of
values some combination of the two.

Modifications:

- Modify the `DNSResolver` API to return `nil` where only a single value
  is expected (e.g. CNAME).
- Update documentation on `DNSResolver` to clarify the expected return
  values when no values are resolved.
- Update the c-ares backend to check for no data when parsing and return
  empty responses
- Update the DNSSD backend to pass in `nil` data to the parser when the
  status is timeout
- Remove the `noData` error code as it shouldn't be reachable anymore

Result:

Queries with no response either return empty or nil
@yim-lee
Copy link
Member

yim-lee commented Mar 4, 2024

@swift-server-bot test this please

@glbrntt glbrntt requested a review from yim-lee March 4, 2024 18:58
@glbrntt glbrntt merged commit 6e94db5 into apple:main Mar 5, 2024
@glbrntt glbrntt deleted the avoid-no-data branch March 5, 2024 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants