-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Josverl/traceback
Show backtrace when a micropython exception occurs
- Loading branch information
Showing
37 changed files
with
781 additions
and
598 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ scratch | |
|
||
.idea | ||
.coverage | ||
.coverage.* |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"This notebook gives an example of how errors that may occur on the MCU are returned to the notebook.\n", | ||
"\n", | ||
"If an Error or Exception occurs on the MCU, the nodebook will receive a message with the error information.\n", | ||
"The nodebook will then display the traceback and Error or Exeption.\n", | ||
"The traceback is logged as one or more warnings, and the Exception or Error is logged as an error.\n", | ||
"\n", | ||
"- `File \"<stdin>\"` refers to the cell that was executed on the MCU.\n", | ||
"- the line number and function / class names are also given.\n", | ||
"- if a module is loaded from the MCU filesystem, filename is also logged.\n", | ||
"\n", | ||
"_Note 1:_ If the log level is set to DEBUG or TRACE additional information will be logged. \n", | ||
"_Note 2:_ Use the `%xmode` magic to limit the amount of information that is displayed when an exception is raised.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"MicroPythonMagic(Magics) options\n", | ||
"------------------------------\n", | ||
"MicroPythonMagic.loglevel=<UseEnum>\n", | ||
" Choices: any of ['TRACE', 'DEBUG', 'INFO', 'WARNING', 'ERROR']\n", | ||
" Current: <LogLevel.WARNING: 'WARNING'>\n", | ||
"MicroPythonMagic.timeout=<Float>\n", | ||
" Current: 300.0\n", | ||
"MicroPythonMagic.xmode=<Unicode>\n", | ||
" Current: 'Minimal'\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%config MicroPythonMagic.loglevel = \"WARNING\"\n", | ||
"%config MicroPythonMagic" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"tags": [ | ||
"raises-exception" | ||
] | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Current ip.InteractiveTB.mode='Minimal'\n" | ||
] | ||
}, | ||
{ | ||
"ename": "ConnectionError", | ||
"evalue": "no device found", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[1;31mConnectionError\u001b[0m\u001b[1;31m:\u001b[0m no device found\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# %%micropython\n", | ||
"import sys\n", | ||
"\n", | ||
"\n", | ||
"def lumberjack():\n", | ||
" bright_side_of_death()\n", | ||
"\n", | ||
"\n", | ||
"def bright_side_of_death():\n", | ||
" return tuple()[0]\n", | ||
"\n", | ||
"\n", | ||
"print(\"Hello World\")\n", | ||
"lumberjack()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%micropython --writefile petstore.py --reset\n", | ||
"\n", | ||
"class Parrot:\n", | ||
" def __init__(self):\n", | ||
" self.state = 'ALIVE'\n", | ||
"\n", | ||
" def pinin_for_fjords(self):\n", | ||
" self.state = 'DEAD'\n", | ||
"\n", | ||
" def is_pinin(self):\n", | ||
" return self.state == 'DEAD'\n", | ||
" \n", | ||
" def feed(self):\n", | ||
" self.state = 'ALIVE'\n", | ||
" \n", | ||
" def is_stiff(self):\n", | ||
" return self.state in ['STIFF', 'DEAD']\n", | ||
"\n", | ||
"\n", | ||
"class NorwegianBlue(Parrot):\n", | ||
" def is_stiff(self):\n", | ||
" raise AssertionError('I am not dead yet!')\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"tags": [ | ||
"raises-exception" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# %%micropython\n", | ||
"\n", | ||
"from petstore import NorwegianBlue # type: ignore\n", | ||
"\n", | ||
"polly = NorwegianBlue()\n", | ||
"\n", | ||
"print(polly.state)\n", | ||
"polly.pinin_for_fjords()\n", | ||
"print(polly.state)\n", | ||
"polly.feed()\n", | ||
"polly.is_stiff()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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.