Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: recover panics within libraries and convert to informative errors #71

Merged
merged 1 commit into from
Jul 18, 2024

Conversation

efd6
Copy link
Collaborator

@efd6 efd6 commented Jul 18, 2024

Wrap extensions that could panic with a recover to collect the latest mito/lib line in a stack trace and decorate the error with the failing AST node's ID. Libs that do not have a reasonable potential to panic are not included in this change: crypto, send, strings, time and try.

Example behaviour change with an inserted nil deref to provoke a panic.

    --- FAIL: TestScripts/get (0.27s)
        testscript.go:397: 
            > mito -use http,collections src.cel
            [stderr]
            failed eval: ERROR: <input>:1:4: runtime error: invalid memory address or nil pointer dereference: lib.httpLib.doGet lib/http.go:482
             | get("http://www.example.com/").drop([
             | ...^
            [exit status 1]
            FAIL: testdata/get.txt:1: unexpected command failure

versus the current behaviour

    --- FAIL: TestScripts/get (0.27s)
        testscript.go:397: 
            > mito -use http,collections src.cel
            [stderr]
            failed eval: internal error: runtime error: invalid memory address or nil pointer dereference
            [exit status 1]
            FAIL: testdata/get.txt:1: unexpected command failure

There is no significant impact on performance.

                                           │   old.bench   │              new.bench               │
                                           │    sec/op     │    sec/op     vs base                │
Mito/hello_world_static/unfolded-20           545.6n ±  3%   560.6n ±  5%        ~ (p=0.123 n=10)
Mito/hello_world_static/folded-20             578.3n ±  7%   578.9n ±  6%        ~ (p=0.631 n=10)
Mito/hello_world_object_static/unfolded-20    3.467µ ±  5%   3.513µ ±  3%        ~ (p=0.436 n=10)
Mito/hello_world_object_static/folded-20      3.507µ ±  4%   3.490µ ±  2%        ~ (p=0.529 n=10)
Mito/nested_static/unfolded-20                13.75µ ±  3%   13.80µ ±  4%        ~ (p=0.912 n=10)
Mito/nested_static/folded-20                  13.67µ ±  8%   13.52µ ±  4%        ~ (p=0.529 n=10)
Mito/encode_json_static/unfolded-20           14.28µ ±  6%   14.06µ ±  4%        ~ (p=0.912 n=10)
Mito/encode_json_static/folded-20             1.032µ ±  8%   1.027µ ±  7%        ~ (p=0.853 n=10)
Mito/nested_collate_static/unfolded-20        6.011µ ±  2%   5.888µ ±  4%        ~ (p=0.247 n=10)
Mito/nested_collate_static/folded-20          1.463µ ±  9%   1.500µ ±  3%        ~ (p=0.529 n=10)
Mito/hello_world_state/unfolded-20            649.6n ±  7%   650.6n ±  5%        ~ (p=0.912 n=10)
Mito/hello_world_state/folded-20              638.9n ±  4%   648.3n ±  6%        ~ (p=0.912 n=10)
Mito/hello_world_object_state/unfolded-20     3.699µ ±  6%   3.708µ ±  4%        ~ (p=0.853 n=10)
Mito/hello_world_object_state/folded-20       3.570µ ±  6%   3.716µ ±  3%   +4.12% (p=0.005 n=10)
Mito/nested_state/unfolded-20                 11.23µ ±  4%   11.40µ ±  4%        ~ (p=0.516 n=10)
Mito/nested_state/folded-20                   11.13µ ±  5%   11.29µ ±  4%        ~ (p=0.579 n=10)
Mito/encode_json_state/unfolded-20            3.122µ ±  4%   3.143µ ±  7%        ~ (p=0.813 n=10)
Mito/encode_json_state/folded-20              3.128µ ±  3%   3.211µ ±  7%        ~ (p=0.247 n=10)
Mito/nested_collate_list_state/unfolded-20    13.45µ ±  7%   13.34µ ±  4%        ~ (p=0.393 n=10)
Mito/nested_collate_list_state/folded-20      13.39µ ±  7%   13.90µ ±  5%        ~ (p=0.190 n=10)
Mito/nested_collate_map_state/unfolded-20     14.68µ ±  6%   14.45µ ±  7%        ~ (p=0.796 n=10)
Mito/nested_collate_map_state/folded-20       13.78µ ± 10%   14.79µ ±  6%        ~ (p=0.075 n=10)
Mito/null_net/unfolded-20                     74.31µ ±  9%   72.99µ ± 12%        ~ (p=0.481 n=10)
Mito/null_net/folded-20                       478.5n ±  8%   471.3n ±  6%        ~ (p=0.315 n=10)
Mito/hello_world_net/unfolded-20              94.35µ ± 14%   93.67µ ± 12%        ~ (p=0.280 n=10)
Mito/hello_world_net/folded-20                621.2n ±  5%   643.8n ±  5%        ~ (p=0.052 n=10)
Mito/hello_world_object_net/unfolded-20       113.2µ ± 10%   109.3µ ± 15%        ~ (p=0.684 n=10)
Mito/hello_world_object_net/folded-20         3.944µ ±  5%   3.872µ ±  3%        ~ (p=0.280 n=10)
Mito/nested_net/unfolded-20                   146.5µ ± 10%   146.4µ ±  8%        ~ (p=0.529 n=10)
Mito/nested_net/folded-20                    15.707µ ±  4%   8.616µ ± 69%  -45.15% (p=0.000 n=10)
Mito/encode_json_null_net/unfolded-20         96.87µ ± 11%   96.10µ ±  8%        ~ (p=0.971 n=10)
Mito/encode_json_null_net/folded-20           1.287µ ±  5%   1.287µ ±  7%        ~ (p=0.617 n=10)
Mito/encode_json_net/unfolded-20              112.5µ ± 41%   121.8µ ±  4%        ~ (p=0.063 n=10)
Mito/encode_json_net/folded-20                1.099µ ±  8%   1.101µ ±  8%        ~ (p=1.000 n=10)
Mito/nested_collate_list_net/unfolded-20      147.3µ ±  7%   150.2µ ±  7%        ~ (p=0.218 n=10)
Mito/nested_collate_list_net/folded-20        1.678µ ±  5%   1.661µ ±  2%        ~ (p=0.225 n=10)
Mito/nested_collate_map_net/unfolded-20       152.4µ ±  6%   164.1µ ±  7%   +7.68% (p=0.023 n=10)
Mito/nested_collate_map_net/folded-20         1.644µ ±  5%   1.734µ ±  8%        ~ (p=0.063 n=10)
geomean                                       6.813µ         6.772µ         -0.60%

@efd6 efd6 requested a review from a team July 18, 2024 06:14
@efd6 efd6 self-assigned this Jul 18, 2024
@efd6 efd6 marked this pull request as ready for review July 18, 2024 06:35
@efd6 efd6 force-pushed the catch_panics branch 3 times, most recently from eb68e7e to a5dc3d6 Compare July 18, 2024 09:30
Wrap extensions that could panic with a recover to collect the latest
mito/lib line in a stack trace and decorate the error with the failing
AST node's ID. Libs that do not have a reasonable potential to panic are
not included in this change: crypto, send, strings, time and try.
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@efd6 efd6 merged commit eba27f3 into dev Jul 18, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants