-
Notifications
You must be signed in to change notification settings - Fork 122
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
fix: remove ops.main.main deprecation warning, and avoid warnings in action output #1496
Merged
tonyandrewmeyer
merged 13 commits into
canonical:main
from
tonyandrewmeyer:cleaner-warnings-1460
Jan 23, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a1dfa23
Capture warnings via the logging system.
tonyandrewmeyer dd74ea6
Adjust the stack level dynamically.
tonyandrewmeyer 19067bc
Use a logging.warning, and wrap it so it happens later.
tonyandrewmeyer bfdb2d4
Clarify comment.
tonyandrewmeyer bda9c1a
Remove unnecessary change.
tonyandrewmeyer 2aba608
Remove unnecessary change.
tonyandrewmeyer 1e1c724
Go back to issuing a real warning.
tonyandrewmeyer 138fc56
Remove the ops.main.main deprecation warning, as per Charm-Tech discu…
tonyandrewmeyer 3a7437a
Capture warnings via the logging system.
tonyandrewmeyer a589f26
Adjust showwarning, not formatwarning.
tonyandrewmeyer 3bd3f98
Customising showwarning means actually doing, not formatting.
tonyandrewmeyer 5c5b87a
Match the upstream signature.
tonyandrewmeyer dfb4a7a
Keep validating that the legacy calls work, just don't verify they ha…
tonyandrewmeyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about using
warnings.formatwarning(...)
to replicate what showwarning does, that is tries to load the source code and show where the warning was issued?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like unstructured log entries that have newlines in them, and I don't think it's ideal to have code snippets in the Juju debug log. However, we do both of those for exceptions already, so perhaps that doesn't matter. However, I don't think it's that useful for warnings. The default warnings formatter looks like:
That second line is telling me nothing that the first line hasn't already. Maybe the line has something other than the
warnings.warn
call that provides extra context, but in my experience that's unusual.That would currently show something like:
I feel like that's a better form for an unstructured log message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that depends on whether the end user looks at single messages are series of messages.
Don't call foo(), use the new bar() instead
is great if there's a single call to foo(), and not so much if there are hundreds, or if there's no obvious call, as in a case of being called viagetattr(<computed>)()
.I can see benefits for both alternatives, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you still have the filename and the line number. You don't have the exact line of code, but assuming you have access to it, it's trivial to open that file and go to that line number. You don't get a full traceback with the default formatter, so you only have the line the warning was pointing at - which is hopefully using a stacklevel that is one up from the actual
warning.warn
call.For example:
When
_on_something
is called, there will be a Juju log entry that points you at charm.py to the line with "# first one", and whenon_something_else
is called, there will be a Juju log entry that points you at charm.py to the line with "# second one".If we include the actual code, like the default formatter, then you'd also have in the Juju debug log those actual lines of code, but I don't think this really gains you much (especially when it's a warning aimed at the developer, who will have access to the code) - and it saves having a multi-line log entry.