Skip to content

Commit

Permalink
exc
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Jan 18, 2025
1 parent b46e5c5 commit cff1f45
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion execnb/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def render_output(out):
if d := _g('image/svg+xml'): return d

return ''

return '\n'.join(map(render_output, outputs))

# %% ../nbs/02_shell.ipynb
Expand Down
57 changes: 56 additions & 1 deletion nbs/02_shell.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,61 @@
"o"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is how IPython formats exceptions internally:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.core.ultratb import VerboseTB\n",
"formatter = VerboseTB(color_scheme='Linux')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n",
"\u001b[1;31mRecursionError\u001b[0m Traceback (most recent call last)\n",
"Cell \u001b[1;32mIn[31], line 1\u001b[0m\n",
"\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m: f()\n",
"\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n",
"\u001b[0;32m 3\u001b[0m ex \u001b[38;5;241m=\u001b[39m e\n",
"\n",
"Cell \u001b[1;32mIn[19], line 4\u001b[0m, in \u001b[0;36mf\u001b[1;34m()\u001b[0m\n",
"\u001b[1;32m----> 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mf\u001b[39m(): \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"\n",
"Cell \u001b[1;32mIn[19], line 4\u001b[0m, in \u001b[0;36mf\u001b[1;34m()\u001b[0m\n",
"\u001b[1;32m----> 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mf\u001b[39m(): \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"\n",
" \u001b[1;31m[... skipping similar frames: f at line 4 (2974 times)]\u001b[0m\n",
"\n",
"Cell \u001b[1;32mIn[19], line 4\u001b[0m, in \u001b[0;36mf\u001b[1;34m()\u001b[0m\n",
"\u001b[1;32m----> 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mf\u001b[39m(): \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"\n",
"\u001b[1;31mRecursionError\u001b[0m: maximum recursion depth exceeded\n"
]
}
],
"source": [
"try: f()\n",
"except Exception as e:\n",
" ex = e\n",
" print(formatter.text(type(e), e, e.__traceback__))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -992,7 +1047,7 @@
" if d := _g('image/svg+xml'): return d\n",
" \n",
" return ''\n",
" \n",
"\n",
" return '\\n'.join(map(render_output, outputs))"
]
},
Expand Down

0 comments on commit cff1f45

Please sign in to comment.