Skip to content

Commit cff1f45

Browse files
committed
exc
1 parent b46e5c5 commit cff1f45

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

execnb/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def render_output(out):
188188
if d := _g('image/svg+xml'): return d
189189

190190
return ''
191-
191+
192192
return '\n'.join(map(render_output, outputs))
193193

194194
# %% ../nbs/02_shell.ipynb

nbs/02_shell.ipynb

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,61 @@
844844
"o"
845845
]
846846
},
847+
{
848+
"cell_type": "markdown",
849+
"metadata": {},
850+
"source": [
851+
"This is how IPython formats exceptions internally:"
852+
]
853+
},
854+
{
855+
"cell_type": "code",
856+
"execution_count": null,
857+
"metadata": {},
858+
"outputs": [],
859+
"source": [
860+
"from IPython.core.ultratb import VerboseTB\n",
861+
"formatter = VerboseTB(color_scheme='Linux')"
862+
]
863+
},
864+
{
865+
"cell_type": "code",
866+
"execution_count": null,
867+
"metadata": {},
868+
"outputs": [
869+
{
870+
"name": "stdout",
871+
"output_type": "stream",
872+
"text": [
873+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n",
874+
"\u001b[1;31mRecursionError\u001b[0m Traceback (most recent call last)\n",
875+
"Cell \u001b[1;32mIn[31], line 1\u001b[0m\n",
876+
"\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m: f()\n",
877+
"\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",
878+
"\u001b[0;32m 3\u001b[0m ex \u001b[38;5;241m=\u001b[39m e\n",
879+
"\n",
880+
"Cell \u001b[1;32mIn[19], line 4\u001b[0m, in \u001b[0;36mf\u001b[1;34m()\u001b[0m\n",
881+
"\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",
882+
"\n",
883+
"Cell \u001b[1;32mIn[19], line 4\u001b[0m, in \u001b[0;36mf\u001b[1;34m()\u001b[0m\n",
884+
"\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",
885+
"\n",
886+
" \u001b[1;31m[... skipping similar frames: f at line 4 (2974 times)]\u001b[0m\n",
887+
"\n",
888+
"Cell \u001b[1;32mIn[19], line 4\u001b[0m, in \u001b[0;36mf\u001b[1;34m()\u001b[0m\n",
889+
"\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",
890+
"\n",
891+
"\u001b[1;31mRecursionError\u001b[0m: maximum recursion depth exceeded\n"
892+
]
893+
}
894+
],
895+
"source": [
896+
"try: f()\n",
897+
"except Exception as e:\n",
898+
" ex = e\n",
899+
" print(formatter.text(type(e), e, e.__traceback__))"
900+
]
901+
},
847902
{
848903
"cell_type": "code",
849904
"execution_count": null,
@@ -992,7 +1047,7 @@
9921047
" if d := _g('image/svg+xml'): return d\n",
9931048
" \n",
9941049
" return ''\n",
995-
" \n",
1050+
"\n",
9961051
" return '\\n'.join(map(render_output, outputs))"
9971052
]
9981053
},

0 commit comments

Comments
 (0)