#source #location #attach #moon-bit #traceback #source-map

app mbtmap

Attach source location to MoonBit traceback

2 releases

0.1.1 Oct 9, 2024
0.1.0 Oct 9, 2024

#102 in WebAssembly

Download history 311/week @ 2024-10-06 41/week @ 2024-10-13

352 downloads per month

MIT/Apache

12KB
126 lines

MoonBit Source Mapper (mbtmap)

This tool filters traceback generated by moon run -g, automatically attaches source location resolved from sourcemap.

Install it with cargo install mbtmap, pass the location of source map and pipe stderr from moon run -g to it. For example on bash, use |&:

moon run -g src/bin/main.mbt |& mbtmap target/wasm-gc/debug/build/bin/bin.wasm.map
 RuntimeError: unreachable
-    at Option::unwrap|@moonbitlang/minimbt/closure.LowType|.fn/653 (wasm://wasm/001ac3c6:wasm-function[695]:0x112cd)
+    at Option::unwrap|@moonbitlang/minimbt/closure.LowType|.fn/653 (wasm://wasm/001ac3c6:wasm-function[695]:0x112cd /home/nkid00/.moon/lib/core/builtin/option.mbt:34:13)
-    at $moonbitlang/minimbt/wasm.emit_inst.fn/979 (wasm://wasm/001ac3c6:wasm-function[1073]:0x2a182)
+    at $moonbitlang/minimbt/wasm.emit_inst.fn/979 (wasm://wasm/001ac3c6:wasm-function[1073]:0x2a182 src/wasm/wasm.mbt:524:9)
-    at $moonbitlang/minimbt/wasm.emit_inst.fn/979 (wasm://wasm/001ac3c6:wasm-function[1073]:0x2a004)
+    at $moonbitlang/minimbt/wasm.emit_inst.fn/979 (wasm://wasm/001ac3c6:wasm-function[1073]:0x2a004 src/wasm/wasm.mbt:496:28)
-    at $moonbitlang/minimbt/wasm.emit_inst.fn/979 (wasm://wasm/001ac3c6:wasm-function[1073]:0x2a004)
+    at $moonbitlang/minimbt/wasm.emit_inst.fn/979 (wasm://wasm/001ac3c6:wasm-function[1073]:0x2a004 src/wasm/wasm.mbt:496:28)
-    at $moonbitlang/minimbt/wasm.emit_inst.fn/979 (wasm://wasm/001ac3c6:wasm-function[1073]:0x29c44)
+    at $moonbitlang/minimbt/wasm.emit_inst.fn/979 (wasm://wasm/001ac3c6:wasm-function[1073]:0x29c44 src/wasm/wasm.mbt:419:30)
 error: failed to run

Caveat if piping from moon run -g

If stdin of mbtmap is piped from moon run -g, the sourcemap may be stale after compilation and its content won't update before program and moon exit. Mbtmap will wait until stdin has been closed to try to make sure sourcemap has been freshly emitted and then resolve source locations. If this is not applicable or interactive is needed, pass -l option to mbtmap to fall back to line-buffered filter. This way, it is necessary to build and generate fresh sourcemap beforehand.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~6.5–9MB
~180K SLoC