feat: Source Map v3 generation with runtime traceback remapping - #570
Open
tinovyatkin wants to merge 16 commits into
Open
feat: Source Map v3 generation with runtime traceback remapping#570tinovyatkin wants to merge 16 commits into
tinovyatkin wants to merge 16 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #493
Summary
Adds opt-in Source Map v3 generation (the language-agnostic JS-ecosystem format) plus an injected Python runtime that remaps uncaught-exception tracebacks back to the original source files — analogous to
node --enable-source-maps. Full design:docs/source-maps.md.CLI
--sourcemap[=linked|inline|external](esbuild-style; bare flag =linked, orinlinewith--stdout;linked/external+--stdoutis rejected with a suggestion)--sources-content=<bool>overrides the mode-dependentsourcesContentdefault (omitted forinline, embedded forlinked/external)cribo.tomlequivalents:sourcemap,sources-contentHow it works
TextRanges). Each aligned statement yields one line-level mapping; divergent subtrees are skipped defensively. Serialization viaoxc_sourcemap(pinned=8.1.2).__future__imports). Lazy by design — zero file access, env reads, parsing, or decoding until the first uncaught exception. The decoder streams the map in constant memory (backward EOF scan for inline data URLs, chunk-aligned base64, escape-aware JSON field scanner, six-int VLQ state machine that only resolves the traceback's needed lines and exits early), and falls back streaming →json.loads→ previous hook, never masking the original error.inlinealways on (CRIBO_SOURCE_MAPS=0kill switch);linkedactive iff the sibling.mapexists at run time;externalgated onCRIBO_SOURCE_MAPS=1(or a path to the map).sys.excepthook,threading.excepthook,sys.unraisablehook; CPython-style chain rendering and repeated-frame collapsing.Testing
file:linefor inlined, wrapper, and entry modules--stdoutinterplay, config keys,sourcesContentmatrix, runtime activation matrix, thread/unraisable remapping, and a duress suite —RecursionError(collapsed + remapped),MemoryErrorunder a 512 MBRLIMIT_AS(still remaps), FD exhaustion underRLIMIT_NOFILE(clean fallback), and a laziness test (unreadable map + successful run = silent)sourcesContent, backward EOF scan, base64 chunk alignment, json fallback parity)sourcemap_fixtures opt into--sourcemap=linkedand gain a normalized, path-freesource_map@<fixture>mapping snapshot; two fixtures addedcargo clippy --workspace --all-targetsis clean; full suite 333/334 (the one failure,test_cli_stdout::test_directory_entry_empty_fails, is a pre-existing environment-specific snapshot mismatch, confirmed on the pristine tree)Known limitations (documented)
traceback.format_exc()) is not remapped — only the installed hooks re-renderSummary by CodeRabbit
New Features
Documentation
Tests