in google/generativeai/notebook/magics_engine.py [0:0]
def execute_cell(self, line: str, cell_content: str):
"""Executes the supplied magic line and cell payload."""
cell = _clean_cell(cell_content)
placeholders = prompt_utils.get_placeholders(cell)
try:
handler, parsed_args, post_processing_fns = self._get_handler(line, placeholders)
return handler.execute(parsed_args, cell, post_processing_fns)
except argument_parser.ParserNormalExit as e:
if self._ipython_env is not None:
e.set_ipython_env(self._ipython_env)
# ParserNormalExit implements the _ipython_display_ method so it can
# be returned as the output of this cell for display.
return e
except argument_parser.ParserError as e:
e.display(self._ipython_env)
# Raise an exception to indicate that execution for this cell has
# failed.
# The exception is re-raised as SystemExit because Colab automatically
# suppresses traceback for SystemExit but not other exceptions. Because
# ParserErrors are usually due to user error (e.g. a missing required
# flag or an invalid flag value), we want to hide the traceback to
# avoid detracting the user from the error message, and we want to
# reserve exceptions-with-traceback for actual bugs and unexpected
# errors.
error_msg = "Got parser error: {}".format(e.msgs()[-1]) if e.msgs() else ""
raise SystemExit(error_msg) from e