-
Notifications
You must be signed in to change notification settings - Fork 75
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
Better unexpected exception msgs #2883
Conversation
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. |
🌎 This PR changes translatable messages. 🌏 Please select which scenarios apply. For further explanation, please read our policy on message changes.
|
0b86695
to
e2415ea
Compare
uaclient/util.py
Outdated
|
||
def get_user_or_root_log_path() -> str: | ||
if we_are_currently_root(): | ||
return "/var/log/ubuntu-advantage.log" |
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.
We can extract that information directly through the UAConfig
object. Even though users shouldn't change that option, it is still safer to consume that from an UAConfig
objectt.
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.
Thank you for this suggestion! I was wondering if there was somewhere I could consume this info from, so thank you for pointing me in the right direction
uaclient/util.py
Outdated
if we_are_currently_root(): | ||
return "/var/log/ubuntu-advantage.log" | ||
else: | ||
return "~/.cache/ubuntu-pro/ubuntu-pro.log" |
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 think we can at least define part of this path on the defaults
module and reuse it here.
This would even be useful for other places where we specify the non-root log path, like the log
module
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 think the log module should have a function that returns the non-root log file location - we can probably use that here
uaclient/messages/__init__.py
Outdated
To file a bug run: ubuntu-bug ubuntu-advantage-tools""" | ||
Unexpected error(s) occurred: {error_msg} | ||
For more details, see the log: {log_path} | ||
First, try searching online for solutions to this error. |
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 if your point is that we could have more.. ahem, sensible wording, then yes we could
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.
Brb gonna go run this through chatGPT to make it more friendly.
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.
It could be as simple as adding an "if", e.g. "If you think this is a bug, please run: ubuntu-bug ubuntu-advantage-tools"
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 was under the impression that the "First, try searching online for solutions to this error." was the issue not the "Otherwise, file a bug using the command: ubuntu-bug ubuntu-advantage-tools"?
(Although i do agree that even the latter could use less imperative wording.)
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.
Putting this all together. How does the following sound?
Consider searching online for solutions to this error.
Or, if you think this is a bug, please run: ubuntu-bug ubuntu-advantage-tools
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.
Sorry I didn't fully explain my suggestion well.
I meant that I think we don't need to explicitly ask the user to search online at all (even though I'm the one who suggested this). Seeing it written out feels a little too much like we're pushing too much responsibility on the user.
I do still think that the wording "To file a bug run: ubuntu-bug ubuntu-advantage-tools" or similar is too imperative though. So my idea is to only add a conditional ("if") to that suggestion.
I think the "if" suggests enough that it isn't necessarily a bug and could be worth searching online for.
So I think in total it would be:
Unexpected error(s) occurred: {error_msg}
For more details, see the log: {log_path}
If you think this is a bug, please run: ubuntu-bug ubuntu-advantage-tools
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.
Okay if you are taking that requirement away, then yes I agree the "if you think this is a bug" preamble helps a lot. The search online message did feel quite pushy so I'm good with this!
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.
Thank you! And sorry for flip-flopping on that idea 🙃
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.
No worries! Thank you for re-evaluating this change's requirements :)
uaclient/messages/__init__.py
Outdated
Unexpected error(s) occurred. | ||
For more details, see the log: /var/log/ubuntu-advantage.log | ||
To file a bug run: ubuntu-bug ubuntu-advantage-tools""" | ||
Unexpected error(s) occurred: {error_msg} |
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.
While we're editing this - do we need the "(s)" after "error" here @lucasmoura @renanrodrigo? (Is there any chance we'll display more than one error?)
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.
The only place I saw that used this error message and has multiple errors it reports is in contract.py. But it seems like it generates a separate error for each unexpected exception, instead of combining all the messages into one singular error?
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.
yeah we can use the singular I guess
If many errors occur, then one error occurred
808ffa9
to
6f35816
Compare
The error message is being changed per the requirements of issue #2600. This means that translations will need to be updated for the new error message. |
abf9c74
to
f66c48a
Compare
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.
Looking good! Some small nits
uaclient/cli/tests/test_cli.py
Outdated
@@ -508,6 +511,7 @@ def test_errors_handled_gracefully( | |||
m_log_exception, | |||
m_event_info, | |||
m_delete_cache_key, | |||
# _m_get_user_or_root_log_path, |
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.
This looks left behind by mistake
# _m_get_user_or_root_log_path, |
@@ -534,6 +537,7 @@ def test_attach_when_one_service_fails_to_enable( | |||
m_process_entitlement_delta, | |||
m_enable_order, | |||
_m_attachment_data_file_write, | |||
# _m_get_user_or_root_log_path, |
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.
same here
# _m_get_user_or_root_log_path, |
uaclient/log.py
Outdated
if util.we_are_currently_root(): | ||
return UAConfig().log_file | ||
else: | ||
return "~/.cache/" + defaults.USER_CACHE_SUBDIR + "/ubuntu-pro.log" |
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.
Since we only call this when non-root, let's re-use the function below
return "~/.cache/" + defaults.USER_CACHE_SUBDIR + "/ubuntu-pro.log" | |
return get_user_log_file() |
uaclient/tests/test_log.py
Outdated
|
||
|
||
class TestLogHelpers: | ||
def test_get_user_or_root_log_file_path(self): |
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.
This looks like a good set of tests, but let's use parametrization and mock decorators to follow the patterns in the rest of the codebase. Something like this:
def test_get_user_or_root_log_file_path(self): | |
@pytest.mark.parametrize( | |
[ | |
"we_are_currently_root", | |
"expected", | |
], | |
[ | |
(True, "cfg_log_file"), | |
(False, "user_log_file"), | |
] | |
) | |
@mock.patch("uaclient.log.get_user_log_file", return_value="user_log_file") | |
@mock.patch("uaclient.config.UAConfig.log_file", new_callable=mock.PropertyMock, return_value="cfg_log_file") | |
@mock.patch("uaclient.util.we_are_currently_root") | |
def test_get_user_or_root_log_file_path( | |
self, | |
m_we_are_currently_root, | |
m_cfg_log_file, | |
m_get_user_log_file, | |
we_are_currently_root, | |
expected | |
): |
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.
@a-dubs sorry, I just noticed a confusing error in my suggestion above - the mock decorators were in the wrong order. It should be fixed now
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.
thank you! will implement these changes now. Will break the last portion of the test out into a different function because it does not make sense with the parameterization.
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.
nevermind I'm just going to get rid of that test case because it is redundant.
31df360
to
e1292ae
Compare
Message for Unexpected errors is now a formatted string that takes in an error message so that the original error message is no longer hidden from the end user. Fixes: #2600
added util function to get proper log path based on if currently root or not
e1292ae
to
bb3535f
Compare
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.
This looks good - thank you!
Why is this needed?
The unexpected error message does not reflect accurate log location when run by non root, and also the error message obfuscates the original error message so the end user has no context for what actually went wrong. This PR fixes that.
Changes
messages.UnexpectedError
from aNamedMessage
to aFormattedNamedMessage
so that it must be formatted with a string representing an exception/error message to give better context on what errors actually occurred.Please Squash this PR with this commit message
cli: improved cli/log message for unexpected errors
Fixes: #2600
Test Steps
Checklist
Does this PR require extra reviews?