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

Log the exception if bot fails #74

Merged
merged 1 commit into from
Dec 30, 2022
Merged

Conversation

link2xt
Copy link
Contributor

@link2xt link2xt commented Dec 30, 2022

No description provided.

Copy link
Contributor

@missytake missytake left a comment

Choose a reason for hiding this comment

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

Hm, doesn't work for me - I raised a ValueError somewhere in the code, but the output just said:

2022-12-30T22:10:30.773533816Z 0.01 [events-bot] DC_EVENT_INFO data1=0 data2=src/scheduler.rs:324: starting smtp loop
2022-12-30T22:10:30.773821563Z 0.01 [events-bot] DC_EVENT_INFO data1=0 data2=src/scheduler.rs:517: scheduler is running
2022-12-30T22:10:30.774288545Z 0.01 [events-bot] DC_EVENT_INFO data1=0 data2=src/location.rs:603: Location loop is waiting for 24h 0m 0s or interrupt
2022-12-30T22:10:30.777363951Z bot received an unexpected error , exiting now
2022-12-30T22:10:30.777424861Z 0.01 [events-bot] DC_EVENT_INFO data1=0 data2=src/ephemeral.rs:544: Ephemeral loop waiting for deletion in 24h 0m 0s or interrupt

@link2xt
Copy link
Contributor Author

link2xt commented Dec 30, 2022

@missytake I pushed another commit to format with repr(), so it also prints the error class. But otherwise it's ok that ValueError() is formatted like this:

>>> print(ValueError())

>>>

@missytake
Copy link
Contributor

2022-12-30T22:46:19.788044943Z 0.00 [events-bot] DC_EVENT_INFO data1=0 data2=src/location.rs:603: Location loop is waiting for 24h 0m 0s or interrupt
2022-12-30T22:46:19.793593927Z 0.01 [events-bot] DC_EVENT_INFO data1=0 data2=src/contact.rs:1518: Recently seen loop waiting for 24h 0m 0s or interupt
2022-12-30T22:46:19.795321201Z bot received an unexpected error ValueError(), exiting now

Hm, that's a bit better, but can't we log the whole stacktrace? Without the stacktrace it's not very useful.

@missytake
Copy link
Contributor

What about this:

>>> import traceback
>>> try:
...     raise ValueError
... finally:
...     strin = traceback.format_exc()
...     print("tb:", strin)
... 
tb: Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ValueError

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ValueError

@link2xt
Copy link
Contributor Author

link2xt commented Dec 30, 2022

I did it with logging now, what do you think?

Copy link
Contributor

@missytake missytake left a comment

Choose a reason for hiding this comment

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

Looks good now! We could aaaalso make a finally out of it again instead of except, then my IDE doesn't complain about the "too broad exception clause" ;) but except fits as well.

@link2xt
Copy link
Contributor Author

link2xt commented Dec 30, 2022

Exception is probably not accessible from the finally block, because finally runs also when there is no exception.

@link2xt link2xt force-pushed the link2xt/bot-error-print-exception branch from 63aafc3 to 2a46688 Compare December 30, 2022 23:51
@link2xt link2xt merged commit 2a46688 into master Dec 30, 2022
@link2xt link2xt deleted the link2xt/bot-error-print-exception branch December 30, 2022 23:51
@missytake
Copy link
Contributor

because finally runs also when there is no exception.

It doesn't, if only because there is a while 1 in the try clause :D but yes, using except fits better then.

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.

2 participants