Skip to content

feature: Raise PluginError on expected failed code execution #75

Open
@ianhi

Description

@ianhi

Is your feature request related to a problem? Please describe.

I would like to use the docs build execution as a way to check that the code in the docs is staying up to date with the underlying python library. For this to work the docs build must fail when the code raises an exception. That is, a code block containing raise ValueError should stop the docs build with a non-zero returncode.

Describe the solution you'd like

When a code block raises a value error unexpectedly (i.e. not indicated by the returncode option) throw a PluginError

I think this would amount to (maybe optionally) adding a line to this block:

except ExecutionError as error:
identifier = id or extra.get("title", "")
identifier = identifier and f"'{identifier}' "
exit_message = "errors" if error.returncode is None else f"unexpected code {error.returncode}"
log_message = (
f"Execution of {language} code block {identifier}exited with {exit_message}\n\n"
f"Code block is:\n\n{_format_log_details(source_input)}\n\n"
f"Output is:\n\n{_format_log_details(str(error), strip_fences=True)}\n"
)
logger.warning(log_message)
return markdown.convert(str(error))

Describe alternatives you've considered

I don't think there is an alternative method for this plugin.

Additional context

I think this could be configurable, even opt in. And it should still be possible to have errors, in the same way the shell code works.

I'm happy to make a PR implementing this if that's helpful

Metadata

Metadata

Assignees

Labels

featureNew feature or requestinsidersCandidate for Insiders

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions