Skip to content

Conversation

@adityawasudeo
Copy link

Fixes #12264

Add system_raise_on_error configuration option that raises CalledProcessError when shell commands executed via the ! operator return non-zero exit status. This brings similar error-handling behavior to the ! operator as was added to %%bash magic in PR #11287.

Changes:

  • Add system_raise_on_error Bool traitlet config (default: False)
  • Import CalledProcessError from subprocess
  • Modify system_piped() to raise on non-zero exit when enabled
  • Modify system_raw() to raise on non-zero exit when enabled
  • Modify getoutput() to raise on non-zero exit when enabled (uses get_output_error_code to capture exit status)

When enabled, users can halt notebook execution on command failures:
get_ipython().system_raise_on_error = True
!false # Now raises CalledProcessError

Note: A follow-up PR to ipykernel will be needed to support this in Jupyter notebooks, as ZMQInteractiveShell overrides system_piped().

Fixes ipython#12264

Add system_raise_on_error configuration option that raises
CalledProcessError when shell commands executed via the ! operator
return non-zero exit status. This brings similar error-handling
behavior to the ! operator as was added to %%bash magic in PR ipython#11287.

Changes:
- Add system_raise_on_error Bool traitlet config (default: False)
- Import CalledProcessError from subprocess
- Modify system_piped() to raise on non-zero exit when enabled
- Modify system_raw() to raise on non-zero exit when enabled
- Modify getoutput() to raise on non-zero exit when enabled
  (uses get_output_error_code to capture exit status)

When enabled, users can halt notebook execution on command failures:
  get_ipython().system_raise_on_error = True
  !false  # Now raises CalledProcessError

Note: A follow-up PR to ipykernel will be needed to support this
in Jupyter notebooks, as ZMQInteractiveShell overrides system_piped().
@adityawasudeo adityawasudeo marked this pull request as ready for review November 14, 2025 02:48
@adityawasudeo
Copy link
Author

Bumping this. @Carreau would you be able to review it if you have a few minutes to spare? Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell command via bang doesn't have an error on status code

1 participant