Skip to main content

Module result

Module result 

Source
Expand description

Error and result types for the python-ast crate.

This module re-exports anyhow_tracing::Error / anyhow_tracing::Result as the crate-wide Error / Result types so that errors carry structured fields (location, feature, expected, found, …) instead of pre-formatted Strings, which allows tracing/logging consumers — and downstream code that wants to recover the typed payload via anyhow_tracing::Error::downcast_ref — to inspect the original data without having to re-parse a stringified message.

The concrete error kinds (e.g. ParseError, UnsupportedFeature, BinOpNotYetImplemented) are exposed as small thiserror-derived structs that implement std::error::Error. They are wrapped into anyhow_tracing::Error at the construction site (see the helper constructors on this module’s Error-shim re-exports below: parsing_error, codegen_error, unsupported_feature, type_error, syntax_error). The wrapping carries named fields so structured tracing subscribers see fields rather than a stringified blob, while downcasts still recover the typed payload.

Macros§

anyhow
Creates an Error from a format string and arguments, optionally with named fields.
bail
Returns early with an Error.
ensure
Returns early with an Error if a condition is not satisfied.

Structs§

BinOpNotYetImplemented
A binary operator the transpiler does not yet handle. Carries the original BinOp AST node so callers can inspect it without having to re-parse a stringified message.
BoolOpNotYetImplemented
CodeGenError
Code generation failed.
CompareNotYetImplemented
Error
An error type that extends anyhow::Error with named fields.
ExprNotYetImplemented
ExprTypeNotYetImplemented
ParseError
Python parsing failed.
SourceLocation
Location information for error reporting.
StatementNotYetImplemented
SyntaxError
The Python source contained invalid syntax.
TypeError
A type mismatch was detected during code generation.
UnaryOpNotYetImplemented
UnknownType
UnsupportedFeature
A Python feature is not yet implemented in the transpiler.

Traits§

Context
Extension trait for adding context and fields to errors.
IntoErr
Converts foreign error results into the crate’s structured Result type.

Functions§

codegen_error
Create a code generation error with location and helpful guidance.
err_from
Convert any std::error::Error into the crate-wide Error.
error_to_pyerr
Convert a crate Error into a PyErr suitable for returning across the PyO3 boundary. Performs structural downcasting so e.g. SyntaxError becomes PySyntaxError and UnsupportedFeature becomes PyNotImplementedError.
format_error_chain
Render an error and its full source() chain as a single string, so the complete causal context survives type-erased Box<dyn Error> boundaries (whose Display only shows the outermost message).
parsing_error
Create a parsing error with location and helpful guidance.
syntax_error
Create a syntax error with location and helpful guidance.
type_error
Create a type error with location and helpful guidance.
unsupported_feature
Create an unsupported-feature error with location and helpful guidance.

Type Aliases§

Result
A type alias for Result<T, Error>.