Content-Length: 254109 | pFad | https://github.com/adafruit/circuitpython/pull/9692

3C Avoid crashing when printing DeepSleepRequest objects by jepler · Pull Request #9692 · adafruit/circuitpython · GitHub
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

Avoid crashing when printing DeepSleepRequest objects #9692

Merged
merged 2 commits into from
Oct 7, 2024

Conversation

jepler
Copy link

@jepler jepler commented Oct 7, 2024

Before, this would crash trying to print a NULL object. mp_raise_type is the correct way to raise an exception without an associated object or message.

>>> import alarm
>>> try:
...     alarm.exit_and_deep_sleep_until_alarms()
... except BaseException as e:
...     ee = e
... 
>>> ee
DeepSleepRequest()

I also looked at including the deep sleep arguments in the args, but it was confusing because it would seem to print the TimeAlarm rather than the DeepSleepRequest:

=== import alarm
=== try:
===     alarm.exit_and_deep_sleep_until_alarms(
===         alarm.time.TimeAlarm(monotonic_time=12345)
===     )
=== except BaseException as e:
===     print(e)
===     print(e.args)
=== 
<TimeAlarm>
(<TimeAlarm>,)

(that was passing the args to exception_make_new:

-    mp_raise_type(&mp_type_DeepSleepRequest);
+    nlr_raise(mp_obj_exception_make_new(&mp_type_DeepSleepRequest, n_args, 0, pos_args));

)

Closes: #7447
Closes: #9691

dhalbert
dhalbert previously approved these changes Oct 7, 2024
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Thank you!

@dhalbert dhalbert merged commit ef70b7b into adafruit:main Oct 7, 2024
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/adafruit/circuitpython/pull/9692

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy