Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClientConnectorDNSError for differentiating DNS errors from others #8456

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mstojcevich-cisco
Copy link

What do these changes do?

Adds a ClientConnectorError that's specific to DNS resolution errors. See #8455

Are there changes in behavior for the user?

Existing usages should still keep working the same as before since this extends from ClientConnectorError.
Users can now catch ClientConnectorDNSError if they're looking for DNS errors specifically.

Is it a substantial burden for the maintainers to support this?

I can't see this being difficult to maintain since the Resolver abstraction already exists to determine when errors are related to DNS or some other part of the connection.

Related issue number

Fixes #8455

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<type>.rst (e.g. 588.bugfix.rst)

    • if you don't have an issue number, change it to the pull request
      number after creating the PR

      • .bugfix: A bug fix for something the maintainers deemed an
        improper undesired behavior that got corrected to match
        pre-agreed expectations.
      • .feature: A new behavior, public APIs. That sort of stuff.
      • .deprecation: A declaration of future API removals and breaking
        changes in behavior.
      • .breaking: When something public is removed in a breaking way.
        Could be deprecated in an earlier release.
      • .doc: Notable updates to the documentation structure or build
        process.
      • .packaging: Notes for downstreams about unobvious side effects
        and tooling. Changes in the test invocation considerations and
        runtime assumptions.
      • .contrib: Stuff that affects the contributor experience. e.g.
        Running tests, building the docs, setting up the development
        environment.
      • .misc: Changes that are hard to assign to any of the above
        categories.
    • Make sure to use full sentences with correct case and punctuation,
      for example:

      Fixed issue with non-ascii contents in doctest text files
      -- by :user:`contributor-gh-handle`.

      Use the past tense or the present tense a non-imperative mood,
      referring to what's changed compared to the last released version
      of this project.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Jun 11, 2024
with pytest.raises(aiohttp.ClientConnectorError) as excinfo:
async with aiohttp.request("GET", "http://localhost:1/"):
assert False, "never executed" # pragma: no cover
assert not isinstance(excinfo.value, aiohttp.ClientConnectorDNSError)

Check warning

Code scanning / CodeQL

Unreachable code Warning

This statement is unreachable.
Copy link
Author

Choose a reason for hiding this comment

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

Is there a comment I should add to ignore this, or is it fine to proceed with the warning?

Copy link
Member

Choose a reason for hiding this comment

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

There used to be comments back when the tool used to be called LGTM. I'm not sure anymore. But I can click the "dismiss alert" button since I can see that coverage is actually reported on this line.

OTOH, why don't you put the exception into pytest.raises(). That's what's supposed to be checked anyway.

I think CodeQL understands that assert False interrupts the control flow of a test function so it naturally thinks the outer line wouldn't be hit. It'd probably be better to call pytest.fail() there instead. I wonder if wrapping such a call into assert_never() would let us drop the coverage ignore comment as well...

Copy link

codecov bot commented Jun 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.62%. Comparing base (f662958) to head (156cc58).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8456      +/-   ##
==========================================
- Coverage   97.64%   97.62%   -0.03%     
==========================================
  Files         107      107              
  Lines       33067    33075       +8     
  Branches     3885     3887       +2     
==========================================
  Hits        32288    32288              
- Misses        562      568       +6     
- Partials      217      219       +2     
Flag Coverage Δ
CI-GHA 97.53% <100.00%> (-0.03%) ⬇️
OS-Linux 97.22% <100.00%> (+<0.01%) ⬆️
OS-Windows 95.64% <100.00%> (+<0.01%) ⬆️
OS-macOS ?
Py-3.10.11 95.48% <100.00%> (-1.56%) ⬇️
Py-3.10.14 96.98% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 97.18% <100.00%> (-0.03%) ⬇️
Py-3.12.3 97.30% <100.00%> (-0.03%) ⬇️
Py-3.8.10 95.41% <100.00%> (+<0.01%) ⬆️
Py-3.8.18 96.87% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 95.46% <100.00%> (-1.56%) ⬇️
Py-3.9.19 96.97% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 96.54% <100.00%> (+<0.01%) ⬆️
VM-macos ?
VM-ubuntu 97.22% <100.00%> (+<0.01%) ⬆️
VM-windows 95.64% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -0,0 +1 @@
Added `ClientConnectorDNSError` for differentiating DNS resolution errors from other connector errors.
Copy link
Member

Choose a reason for hiding this comment

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

Plz use RST, not MD.

Copy link
Member

Choose a reason for hiding this comment

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

@webknjaz
Copy link
Member

We need to think the DNS-related exception hierarchy through — perhaps it needs a base exception with subtypes. Similar to #6722 (comment).

Additionally, the documentation would need to be updated to list the new exceptions with explanations.

@@ -166,6 +167,14 @@ def __str__(self) -> str:
__reduce__ = BaseException.__reduce__


class ClientConnectorDNSError(ClientConnectorError):
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this should be a connector error, though. Any reasoning?

Copy link
Author

Choose a reason for hiding this comment

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

It's currently a ConnectorError so it would allow existing code that tries to catch ConnectorErrors to keep working. I'm open to taking a different approach though.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I understand. If you read the PR I linked, there were similar concerns, and I know that some bits of this might be breaking. In that instance, we ended up using multiple inheritance and intermediate exceptions in the hierarchy to maximize the compatibility while enabling flexibility and accuracy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate exception for DNS errors
2 participants