8000 An error carries Nix's ErrorInfo · Issue #637 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

An error carries Nix's ErrorInfo #637

Closed
Closed

Description

@Lillecarl

DONE, 2026-09-28. Found by the nanopynix port (#97), 2026-09-27.

Problem

A huggorm error carries two strings, message and colored. Every
nix::Error also carries a nix::ErrorInfo: the level, the primary
position, the evaluation trace and the suggestions. C++ is the only
place that holds it. After translation it is gone.

nanopynix-bindings attaches it to each raised error as info, a dict
(nanopynix-bindings/src/nix_error_info.hh):

  • level, msg, status, is_from_expr;
  • pos: {file, line, column} or None, the file as Pos::print
    renders the origin;
  • traces: up to 32 of {hint, pos}, and truncated;
  • suggestions: a list of strings.

Evidence

Four tests on the huggorm lane fail on excinfo.value.info is None,
all in nanopynix's test_scalar_accessor_semantics.py: max-call-depth
at an explicit depth, runaway recursion at the default depth (inproc
and rpc), and a cyclic value. MissingAttributeError.suggestions is
also [] on huggorm, because it reads info["suggestions"].

Sketch

An ErrorInfo wire value, and a third part in NixError._wire_fields,
so the info crosses the wire as the two strings do. The translator
fills it from e.info(). The caps on traces and on each string stay,
for the reason nanopynix gives: the status details ride in an HTTP/2
header.

Open question: whether a position is huggorm::position_file plus
line and column, the shape Doc and AttrDoc use, or Nix's own
rendering of the origin.

Design, 2026-09-28

Carl chose the typed route from three: typed records, a class bound
to nix::ErrorInfo, or a dict attribute as nanopynix-bindings has.

  • Records. Position, Trace and ErrorInfo are wire values in
    decl/path.py. A record is visible only in the unit that declares
    it, and path holds the translator.
  • One translator. store.py had the same one. nanobind's
    translators serve the whole process, and store imports path, so
    the second one went.
  • The part. NixError._wire_fields gains ("info", "ErrorInfo?"), and reader = "huggorm::error_info" names the C++
    that reads it. pyerrors.chain reads both off the IMPORT, so a
    subclass inherits them, and emits one reader per part beyond the
    message: raise_as(module, name, e, huggorm::error_info<huggorm:: ErrorInfo>). A class with such parts and no reader is refused.
    Interrupted declares two parts, so its catch passes no reader.
  • The reader. cpp/error_info.hpp, a template over the record
    type. It fills the records with designated initialisers, so a
    renamed or reordered field fails to compile. raise_as calls each
    reader inside its try, so a reader that throws cannot escape the
    translator.
  • The position is position_file plus line and column, the shape
    Doc and AttrDoc use. nanopynix-bindings writes Pos::print
    into file, which repeats the line and the column.
  • The trace order is Nix's: addTrace pushes to the front, so the
    list is outermost first. nanopynix-bindings keeps the first 32 and
    says they are the innermost. They are the outermost. huggorm keeps
    the last 32, nearest the error.
  • The wire. FaultCodec put each part with str(), so a record
    part crossed as its repr. It now puts and reads each part through
    WireCodec, as a value's field is. to_dict keeps each part as
    itself for the same reason.

Proved by breaking it

  • The codec back to str() of each part: the round trip fails, and
    so do ten rpc tests, because a message field refuses a string.
  • max_traces at 33: the deep-trace test fails.
  • A chain that passes no readers: five tests fail, the refusal test
    and the four that read info.

Measured on the bindings: { foo = 1; bar = 2; }.fo suggests foo
then bar; 1 + "a" on line 4 is at «string»:4:7; a 40-deep
toJSON keeps 32 frames, the last "while calling the 'throw'
builtin"; max-call-depth has a position and no frames.

nanopynix: each engine answers error_detail(exc), and
translate_nix_exception and the rpc status details both use it. The
five lane tests that read info pass.

Migrated from tasks/100-an-error-carries-nix-s-error-info.md.done.


Assisted-By: Opus 5

Activity

  1. added
    source: huggorm
    on Oct 19, 2026
  2. transferred this issue fromnixidae/huggormon Oct 19, 2026
  3. added theissue type on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: huggorm

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0