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

update connectivity error message #2817

Merged
merged 2 commits into from
Jan 4, 2024

Conversation

lucasmoura
Copy link
Contributor

@lucasmoura lucasmoura commented Oct 30, 2023

Why is this needed?

We want to make connectivity errors clearer and easier to debug for the user. To achieve that, we are now displaying the url that cause the error together with the cause behind the error.

Fixes: #2647

Test Steps

  1. Launch a lxd container
  2. Disable network on container with: lxc config device add NAME eth0 none
  3. Run pro fix USN-4539-1

Expect the following message:

Failed to connect to https://ubuntu.com/security/notices/USN-4539-1.json
[Errno -3] Temporary failure in name resolution 

Checklist

  • I have updated or added any unit tests accordingly
  • I have updated or added any integration tests accordingly
  • Changes here need to be documented, and this was done in:

Does this PR require extra reviews?

  • Yes
  • No

@github-actions
Copy link

github-actions bot commented Oct 30, 2023

🌎 This PR changes translatable messages. 🌏

Please select which scenarios apply. For further explanation, please read our policy on message changes.

  • New messages are being added.
    • We will ask translators to take a look and add translations if they have time, but it will not block this PR.
  • Existing messages are being changed.
    • ⚠️ Please add a comment with justification of why messages are being altered.
    • If the changes are trivial (e.g. a typo fix), then translations must be preserved.
    • If the changes are substantial, then we will ask translators to take a look and update translations if they have time, but it will not block this PR.
  • Existing messages are being deleted.
    • No special action needed.

@github-actions
Copy link

Jira: This PR is not related to a Jira item. (The PR title does not include a SC-#### reference)

GitHub Issues:

Launchpad Bugs: No Launchpad bugs are fixed by this PR. (No commits have LP: #### references)

Documentation: The changes in this PR do not require documentation changes.

👍 this comment to confirm that this is correct.

@lucasmoura
Copy link
Contributor Author

@orndorffgrant @renanrodrigo I am wondering if we should add the HTTP error code if available or if stating the cause is enough for debugging. Let me know what you think

@orndorffgrant
Copy link
Collaborator

I think the HTTP code doesn't hurt and could help

I'm tempted to suggest we combine UrlError and ConnectivityError into one exception class - but it'd be a little tricky to combine them. In order to maintain backwards compatibility, the new class would need to doubly inherit from UbuntuProError and IOError. And we'd need to keep both names pointing to the same class. What do you think?

@lucasmoura
Copy link
Contributor Author

@orndorffgrant I think that is a good idea, since we only raise ConnectivyError exceptions when an UrlError has already happened. We would need to handle the MRO for the __init__ call, which I don't think is a huge problem. The only issue I see is that it will now take more parameters to instantiate a ConnectivityError exception, due to the IOErrorrequirements, which might affect backwards compatibility. But maybe I am overthinking this.

@lucasmoura lucasmoura force-pushed the update-connection-error-message branch from 3cddf26 to a277214 Compare November 8, 2023 09:38
@lucasmoura
Copy link
Contributor Author

We have decided not to add the HTTP response code on the message, since we only raise a ConnectivityError when the issue is not tied to an HTTP error

@lucasmoura lucasmoura force-pushed the update-connection-error-message branch from a277214 to 4096039 Compare November 24, 2023 17:03
UbuntuProError.__init__(self, cause_error=cause_error, url=url)

# Even though we already set those variable through UbuntuProError
# we need to set them again to avoid mype warnings
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# we need to set them again to avoid mype warnings
# we need to set them again to avoid mypy warnings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@lucasmoura lucasmoura force-pushed the update-connection-error-message branch from 4096039 to 3bd5310 Compare November 27, 2023 12:43
Comment on lines 267 to 268
except exceptions.ConnectivityError as e:
LOG.exception(e.cause_error)
raise e
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a couple places where we catch ConnectivityError, log the message, and then re-raise it. Maybe we should log the error when raising it originally in http/init.py and then remove all the catch-log-reraise blocks - what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, I will update the PR

@lucasmoura
Copy link
Contributor Author

@orndorffgrant updated

@lucasmoura lucasmoura force-pushed the update-connection-error-message branch from c41ae38 to db0d395 Compare December 15, 2023 19:22
Copy link
Collaborator

@orndorffgrant orndorffgrant left a comment

Choose a reason for hiding this comment

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

The tiniest of nits so pre-approving, no need for another review from me

"""
environment_vars: \[\]
errors:
- message: 'Failed to connect to .*
Copy link
Collaborator

Choose a reason for hiding this comment

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

(same comment applies to json version above)

I agree it's easiest to make this a regex but I think we can assert a bit more since we know mostly what the URL will be. I think this should work

Suggested change
- message: 'Failed to connect to .*
- message: 'Failed to connect to https://invalidurl.notcanonical.com/v1/resources?architecture=amd64&kernel=(.*)&series=<release>&virt=lxc

Comment on lines 67 to 68
except exceptions.ConnectivityError as e:
raise e
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can delete these now since they're empty :D

Suggested change
except exceptions.ConnectivityError as e:
raise e

Comment on lines 267 to 268
except exceptions.ConnectivityError as e:
raise e
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
except exceptions.ConnectivityError as e:
raise e

Comment on lines 292 to 293
except exceptions.ConnectivityError as e:
raise e
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
except exceptions.ConnectivityError as e:
raise e

Comment on lines 316 to 317
except exceptions.ConnectivityError as e:
raise e
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
except exceptions.ConnectivityError as e:
raise e

@lucasmoura lucasmoura force-pushed the update-connection-error-message branch from db0d395 to 5180fca Compare January 3, 2024 18:33
@lucasmoura
Copy link
Contributor Author

@orndorffgrant updated

Copy link
Collaborator

@orndorffgrant orndorffgrant left a comment

Choose a reason for hiding this comment

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

There are several CI failures. I think they're mostly unrelated but probably worth checking

"""
environment_vars: \[\]
errors:
- message: 'Failed to connect to https://invalidurl.notcanonical.com/v1/resources\?architecture=amd64&kernel=(.*)&series=<release>&virt=lxc
Copy link
Collaborator

Choose a reason for hiding this comment

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

I gave a bad suggestion sorry. I think it's good to check at least the domain name, but it turns out we can't rely on the order of the parameters on xenial

Suggested change
- message: 'Failed to connect to https://invalidurl.notcanonical.com/v1/resources\?architecture=amd64&kernel=(.*)&series=<release>&virt=lxc
- message: 'Failed to connect to https://invalidurl.notcanonical.com/v1/resources(.*)

Since ConnectityError is only raised when we detect an UrlError
exception, we have decided to merge those exceptios. Additionally,
we have also updated the ConnectivityError message to be more explicit
on what the actual error is.

Fixes: #2647
@lucasmoura lucasmoura force-pushed the update-connection-error-message branch from 5180fca to 919c54b Compare January 4, 2024 18:50
@lucasmoura
Copy link
Contributor Author

@orndorffgrant I have fixed the unattached_status test and I for the other ones failing on CI, I wasn't able to reproduce them locally, so I am inclined to say that they are all flaky. But let's see what a second run of CI will tell

@orndorffgrant
Copy link
Collaborator

The bionic fix fail will be fixed by #2897

Merging

@orndorffgrant orndorffgrant merged commit 009f8f5 into main Jan 4, 2024
24 of 25 checks passed
@renanrodrigo renanrodrigo deleted the update-connection-error-message branch January 4, 2024 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Contract server error message should be more specific
3 participants