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

logger: use py3 methods to display the exception #3059

Closed
wants to merge 3 commits into from
Closed

logger: use py3 methods to display the exception #3059

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jan 5, 2020

Related: #1818

Did the best that I could. formatException and formatStack doesn't work for us because of the way we are displaying the traceback and manipulating the title of the exception.

@ghost ghost mentioned this pull request Jan 5, 2020
3 tasks
@ghost ghost requested a review from efiop January 5, 2020 06:22
@ghost
Copy link
Author

ghost commented Jan 5, 2020

Does someone remember why do we have three handlers info, debug, errors?

errors spits out everything starting from WARNING to sys.stderr.

debug prints everything to sys.stdout, excluding errors.

But I don't get info, why do we have debug and info? 🤔
Maybe it does make sense to use print in the codebase instead of logger.info, after all.


EDIT: It is to not include DEBUG messages when INFO is activated. Although, hard to read 😅

@ghost ghost requested review from Suor and casperdcl January 5, 2020 07:56
dvc/logger.py Outdated Show resolved Hide resolved
dvc/logger.py Outdated
if record.exc_info:
_, exception, _ = record.exc_info
cause = exception.__cause__
trace = "".join(traceback.format_exception(*record.exc_info))
Copy link
Contributor

Choose a reason for hiding this comment

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

This should only be formatted under DEBUG if and should somehow include cause traceback. Ideally cause traceback should not be appended, but separated the same as Python does by default.

dvc/logger.py Outdated
message=record.msg or "",
separator=" - " if record.msg and exception.args else "",
exception=exception,
cause=": " + str(cause) if cause else "",
Copy link
Contributor

Choose a reason for hiding this comment

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

This should only be shown in DEBUG mode and should not be shown in the message anyway. Let's use Python default presentation.

Copy link
Author

Choose a reason for hiding this comment

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

@Suor , this would change the previous behavior, I could move that discussion into another issue.
I've my doubts with the way logger is currently implemented and used 😅

@ghost ghost requested a review from Suor January 6, 2020 21:55
dvc/logger.py Outdated Show resolved Hide resolved
Comment on lines -67 to -72
return (
"{color}{levelname}{nc}: {description}" "{stack_trace}\n"
).format(
color=self.color_code.get(record.levelname, ""),
nc=colorama.Fore.RESET,
levelname=record.levelname,
Copy link
Contributor

Choose a reason for hiding this comment

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

@MrOutis Why do we need to make these changes? Isn't the point of this change to just use py3 interfaces? If so, the only thing that should be affected is _parse_exc. Or am I missing something?

Copy link
Author

@ghost ghost Jan 7, 2020

Choose a reason for hiding this comment

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

we are using format_exc. just some reorganization, nothing on the logic changed besides misreading the while loop

Copy link
Contributor

Choose a reason for hiding this comment

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

@MrOutis I understand, but it really widens the scope and makes this hard to review when having simple py3 migration in mind. Something might slip by. 🙁

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @efiop - it's very tempting to fix multiple issues in one go but with a big PR like this it's best to tidy up/reorganise in a follow-up PR.

Copy link
Author

Choose a reason for hiding this comment

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

got it, @efiop , @casperdcl ; I'll take it into account for further PR's 🙂

dvc/logger.py Show resolved Hide resolved
@ghost ghost requested a review from efiop January 7, 2020 01:08
@@ -117,7 +115,7 @@ def test_nested_exceptions(self, caplog):
"{red}ERROR{nc}: message - second: first\n"
"{red}{line}{nc}\n"
"{stack_trace}"
"{red}{line}{nc}\n".format(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please explain why \n are getting removed now?

Copy link
Author

Choose a reason for hiding this comment

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

I found it excessive, maybe not enough reason to do so.

Copy link
Contributor

Choose a reason for hiding this comment

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

@MrOutis The newline is needed there, it is part of the message. I imagine you are trying to solve double newline between the exc and "Having any troubles" footer, right? If so, it is probably worth just removing \n there. But again, this is out of scope for this PR, so let's not touch new lines at all, please roll back this change for now.

Copy link
Author

Choose a reason for hiding this comment

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

Ok

dvc/logger.py Show resolved Hide resolved
dvc/logger.py Show resolved Hide resolved
@ghost
Copy link
Author

ghost commented Jan 7, 2020

Closing this one in favor of #3078

@ghost ghost closed this Jan 7, 2020
@ghost ghost deleted the refactor-logger branch January 7, 2020 05:40
logger.exception("message")
except DvcException as exc:
try:
raise ValueError("third") from exc
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to test how it works without explicit cause. Maybe that is even more important because that is an error in error handler presumably, which we want to fix.

This pull request was closed.
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.

3 participants