astrocook.recipes.errors module#

The exceptions of the recipes (phase 6-bis, PR 3).

A recipe that cannot do what was asked raises a RecipeError, instead of logging the reason and returning 0. It does not log it: the error is logged once, where it is caught (the GUI shows it in a dialog and the status bar, the MCP server passes it to the agent, the worker of the scripts logs it with the line of the script; a Python script gets the exception). Guido’s decisions at the start of PR 3.

Every error says in which recipe it happened and why. The decorator of the recipes (astrocook.recipes.params.typed_recipe()) records each recipe the error goes through, so that an error of a step of a pipeline names the pipeline and the step:

Auto-fit metal doublets → Refit all systems: the region 'nope' is unknown.

The same decorator turns the errors of the core that mean “this data or this value cannot be used” (ValueError, KeyError, OSError) into RecipeFailed, with the original error as its cause; the others, usually bugs, go on as they are, with a note naming the recipe.

exception astrocook.recipes.errors.RecipeError(reason: str)[source]#

Bases: Exception

A recipe could not do what was asked.

reason is why; chain the recipes the error went through, as (category, name, title) from the outermost to the one where it happened (filled by the decorator of the recipes). str() gives the titles and the reason, the message shown to the user.

__init__(reason: str)[source]#
property recipe: str | None#

The recipe where the error happened, as category.name.

enter(category: str, name: str, title: str) → None[source]#

Record a recipe the error goes through (called from the inside out, so each new one is the outermost).

add_note(object, /)#

Exception.add_note(note) – add a note to the exception

args#
with_traceback(object, /)#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception astrocook.recipes.errors.InvalidParameter(reason: str)[source]#

Bases: RecipeError, ValueError

A parameter cannot be converted to its type, or is out of its bounds; the reason names the parameter and the value.

__init__(reason: str)#
add_note(object, /)#

Exception.add_note(note) – add a note to the exception

args#
enter(category: str, name: str, title: str) → None#

Record a recipe the error goes through (called from the inside out, so each new one is the outermost).

property recipe: str | None#

The recipe where the error happened, as category.name.

with_traceback(object, /)#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

chain: List[Tuple[str, str, str]]#
exception astrocook.recipes.errors.RecipeFailed(reason: str)[source]#

Bases: RecipeError

The recipe ran and could not give a result: the data or the session do not allow it (a session that is not open, a file that cannot be read, an expression that cannot be evaluated, …).

__init__(reason: str)#
add_note(object, /)#

Exception.add_note(note) – add a note to the exception

args#
enter(category: str, name: str, title: str) → None#

Record a recipe the error goes through (called from the inside out, so each new one is the outermost).

property recipe: str | None#

The recipe where the error happened, as category.name.

with_traceback(object, /)#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

chain: List[Tuple[str, str, str]]#
exception astrocook.recipes.errors.RecipeCancelled(reason: str)[source]#

Bases: RecipeError

The recipe was cancelled while it ran (the Stop of the GUI, the cancellation of a client of the MCP server, session_cancel): it leaves no new state (phase 6-ter, PR 7-quater). Raised by astrocook.recipes.progress.check_cancelled().

__init__(reason: str)#
add_note(object, /)#

Exception.add_note(note) – add a note to the exception

args#
enter(category: str, name: str, title: str) → None#

Record a recipe the error goes through (called from the inside out, so each new one is the outermost).

property recipe: str | None#

The recipe where the error happened, as category.name.

with_traceback(object, /)#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

chain: List[Tuple[str, str, str]]#
exception astrocook.recipes.errors.MissingPrerequisite(reason: str)[source]#

Bases: RecipeError

The session lacks what the recipe needs (z_em, the resolution, the continuum, …); phase 6-bis, PR 5, fills these in (“Prerequisites of the recipes”).

__init__(reason: str)#
add_note(object, /)#

Exception.add_note(note) – add a note to the exception

args#
enter(category: str, name: str, title: str) → None#

Record a recipe the error goes through (called from the inside out, so each new one is the outermost).

property recipe: str | None#

The recipe where the error happened, as category.name.

with_traceback(object, /)#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

chain: List[Tuple[str, str, str]]#
astrocook.recipes.errors.reason_of(error: BaseException) → str[source]#

The text of an error of the core, as a reason (a KeyError gives its key quoted, not the repr of its arguments).