Repository navigation
Description
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 asPos::print
renders the origin;traces: up to 32 of{hint, pos}, andtruncated;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,TraceandErrorInfoare wire values in
decl/path.py. A record is visible only in the unit that declares
it, andpathholds the translator. - One translator.
store.pyhad the same one. nanobind's
translators serve the whole process, andstoreimportspath, so
the second one went. - The part.
NixError._wire_fieldsgains("info", "ErrorInfo?"), andreader = "huggorm::error_info"names the C++
that reads it.pyerrors.chainreads 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.
Interrupteddeclares 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_ascalls each
reader inside itstry, so a reader that throws cannot escape the
translator. - The position is
position_fileplus line and column, the shape
DocandAttrDocuse. nanopynix-bindings writesPos::print
intofile, which repeats the line and the column. - The trace order is Nix's:
addTracepushes 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.
FaultCodecput each part withstr(), so a record
part crossed as its repr. It now puts and reads each part through
WireCodec, as a value's field is.to_dictkeeps 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_tracesat 33: the deep-trace test fails.- A chain that passes no readers: five tests fail, the refusal test
and the four that readinfo.
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