Class VisitErrorContext#

Inheritance Relationships#

Base Type#

Class Documentation#

class VisitErrorContext : public tvm::ffi::ObjectRef#

Typed payload attached to Error::extra_context to support visit-context-aware error reporting.

The VisitErrorContext captures the reverse_visit_pattern — the chain of nodes visited before an error was thrown — so callers can translate it via FindAccessPaths into a structured access path for richer error messages.

Typical usage:

  1. A recursive visit is instrumented with TVM_FFI_VISIT_BEGIN / _END(node). The deepest detection point throws via TVM_FFI_VISIT_THROW(kind, node), which seeds the context with the throw site; enclosing BEGIN/END pairs append parent nodes on rethrow.

  2. The root catch handler retrieves the context via TryGetFromError(err), then resolves the chain into one or more reflection::AccessPath instances via FindAccessPaths(root, ctx).

  3. The caller uses the AccessPath to enrich the error message with structured position info (e.g., “.body[2].cond.lhs”).

Public Static Functions

static inline Optional<VisitErrorContext> TryGetFromError(const Error &err)#

Get the VisitErrorContext attached to err’s extra_context.

Parameters:

err – The error to inspect.

Returns:

The attached VisitErrorContext, or NullOpt if absent.

static inline Error EnrichVisitError(Error error, const ObjectRef &root) noexcept#

Invoke the exact root type’s visit-error enrichment hook.

Public structural operations call this once at their outer error boundary, after recursive traversal has accumulated VisitErrorContext breadcrumbs, with the original operation input as root. Recursive visitor and mutator methods collect context without calling this helper.

Only errors carrying VisitErrorContext and defined object roots participate. Lookup uses only the exact root dynamic type’s attribute entry. An absent or failing hook leaves the original error unchanged. The borrowed root avoids changing successful mutation ownership semantics.

static Array<reflection::AccessPath> FindAccessPaths(const ObjectRef &root, const VisitErrorContext &visit_context, bool allow_prefix_match = false)#

Find all access paths that match the pattern specified in the VisitErrorContext.

Parameters:
  • root – The root ObjectRef to search from.

  • visit_context – The VisitErrorContext to match against.

  • allow_prefix_match – If true, also report paths where only a prefix of the pattern was matched (i.e., the algorithm descended through some matched records but could not find further matches before reaching a leaf). Default false — only full pattern matches are reported.

Returns:

Array of matched access paths.