Skip to content

Commit

Permalink
prevent execution, pre-render errors notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
christophfink committed Sep 8, 2022
1 parent 70529b3 commit 345fbae
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 16 deletions.
2 changes: 1 addition & 1 deletion source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@
execution_allow_errors = True

# Execute cells only if any of the cells is missing output
jupyter_execute_notebooks = "auto"
jupyter_execute_notebooks = "off"
106 changes: 91 additions & 15 deletions source/notebooks/L6/errors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"tags": [
"raises-exception"
]
},
"outputs": [],
"outputs": [
{
"ename": "SyntaxError",
"evalue": "EOL while scanning string literal (2231829726.py, line 4)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"/var/folders/lp/cjwc88bd3w10sg327y_4ghg0fsk7jj/T/ipykernel_68439/2231829726.py\"\u001b[0;36m, line \u001b[0;32m4\u001b[0m\n\u001b[0;31m print(f\"A wind speed of {wind_speed_km} km/hr is {wind_speed_ms} m/s.)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m EOL while scanning string literal\n"
]
}
],
"source": [
"wind_speed_km = 50\n",
"wind_speed_ms = wind_speed_km * 1000 / 3600\n",
Expand All @@ -70,13 +79,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"tags": [
"raises-exception"
]
},
"outputs": [],
"outputs": [
{
"ename": "TypeError",
"evalue": "unsupported operand type(s) for /: 'str' and 'int'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/var/folders/lp/cjwc88bd3w10sg327y_4ghg0fsk7jj/T/ipykernel_68439/2952723812.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mwind_speed_km\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'30'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mwind_speed_ms\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mconvert_wind_speed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mwind_speed_km\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"A wind speed of {wind_speed_km} km/hr is {wind_speed_ms} m/s.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/var/folders/lp/cjwc88bd3w10sg327y_4ghg0fsk7jj/T/ipykernel_68439/2952723812.py\u001b[0m in \u001b[0;36mconvert_wind_speed\u001b[0;34m(speed)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mconvert_wind_speed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mspeed\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mspeed\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;36m1000\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m3600\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mwind_speed_km\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'30'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mwind_speed_ms\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mconvert_wind_speed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mwind_speed_km\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'int'"
]
}
],
"source": [
"def convert_wind_speed(speed):\n",
" return speed * 1000 / 3600\n",
Expand Down Expand Up @@ -112,7 +134,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -121,13 +143,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"tags": [
"raises-exception"
]
},
"outputs": [],
"outputs": [
{
"ename": "IndexError",
"evalue": "list index out of range",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/var/folders/lp/cjwc88bd3w10sg327y_4ghg0fsk7jj/T/ipykernel_68439/3963876545.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcities\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mIndexError\u001b[0m: list index out of range"
]
}
],
"source": [
"cities[5]"
]
Expand All @@ -150,13 +184,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"tags": [
"raises-exception"
]
},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'stations' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/var/folders/lp/cjwc88bd3w10sg327y_4ghg0fsk7jj/T/ipykernel_68439/2799791259.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mstation_id\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstations\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'stations' is not defined"
]
}
],
"source": [
"station_id = stations[1]"
]
Expand All @@ -179,13 +225,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"tags": [
"raises-exception"
]
},
"outputs": [],
"outputs": [
{
"ename": "IndentationError",
"evalue": "unindent does not match any outer indentation level (<tokenize>, line 3)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<tokenize>\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m print(city)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m unindent does not match any outer indentation level\n"
]
}
],
"source": [
"for city in cities:\n",
" city = city + \" is a city in Europe\"\n",
Expand All @@ -194,13 +249,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {
"tags": [
"raises-exception"
]
},
"outputs": [],
"outputs": [
{
"ename": "IndentationError",
"evalue": "expected an indented block (1297196788.py, line 2)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"/var/folders/lp/cjwc88bd3w10sg327y_4ghg0fsk7jj/T/ipykernel_68439/1297196788.py\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m city = city + \" is a city in Europe\"\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block\n"
]
}
],
"source": [
"for city in cities:\n",
"city = city + \" is a city in Europe\"\n",
Expand All @@ -225,13 +289,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {
"tags": [
"raises-exception"
]
},
"outputs": [],
"outputs": [
{
"ename": "TypeError",
"evalue": "unsupported operand type(s) for /: 'str' and 'int'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/var/folders/lp/cjwc88bd3w10sg327y_4ghg0fsk7jj/T/ipykernel_68439/2693491430.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcities\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'int'"
]
}
],
"source": [
"cities[0] / 5"
]
Expand Down

0 comments on commit 345fbae

Please sign in to comment.