Skip to content

dialyzer: catch parse errors raised from the try/of body in start/1 - #11679

Open
kikofernandez wants to merge 2 commits into
erlang:maintfrom
kikofernandez:kiko/dialyzer/catch-parse-errors-in-try-of-body-start/OTP-20407
Open

kikofernandez wants to merge 2 commits into
erlang:maintfrom
kikofernandez:kiko/dialyzer/catch-parse-errors-in-try-of-body-start/OTP-20407

Conversation

@kikofernandez

@kikofernandez kikofernandez commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

dialyzer_cl_parse:start/0 wrapped argparse:parse/3 in a try ... of ... catch .... A try/of only runs its catch clauses over the guarded expression, not over the of body. postprocess_side_effects/1 and dialyzer_options:build/1 ran in the of body, so throws raised there escaped the catch:

  • the -pa clause calls cl_error/1, which throws {dialyzer_cl_parse_error, _}; and
  • dialyzer_options:check_output_plt/1 throws {dialyzer_error, _}.

Both escaped as {nocatch, ...} past the plain case in dialyzer:plain_cl/0, crashing the CLI with an Erlang stack trace and a non-standard exit status instead of the documented graceful "dialyzer: " + exit code. A common typo error (e.g. -pa on a non-existent directory) hit this path.

Move the case expression inside the try body so the of-body is covered by the catch, and add a throw:{dialyzer_error, Msg} clause for the check_output_plt path. Split start/0 into a thin wrapper over start/1 (which takes the argument list) so the parsing path is testable without spawning a node; start/1 is exported but marked -doc false as it is not part of the public API.

Add dialyzer_cl_SUITE:bad_pa_dir_returns_error/1, which drives start/1 with a non-existent -pa directory and asserts a clean {error, _} return.

dialyzer_cl_parse:start/0 wrapped argparse:parse/3 in a `try ... of ... catch ...`. A try/of only runs its catch clauses over the guarded expression, not over the `of` body. postprocess_side_effects/1 and dialyzer_options:build/1 ran in the `of` body, so throws raised there escaped the catch:

- the `-pa` clause calls `cl_error/1`, which throws `{dialyzer_cl_parse_error, _};` and
- `dialyzer_options:check_output_plt/1` throws `{dialyzer_error, _}`.

Both escaped as `{nocatch, ...}` past the plain case in `dialyzer:plain_cl/0`, crashing the CLI with an Erlang stack trace and a non-standard exit status instead of the documented graceful "dialyzer: <msg>" + exit code. A common typo error (e.g. `-pa` on a non-existent directory) hit this path.

Move the `case` expression inside the `try` body so the of-body is covered by the `catch`, and add a `throw:{dialyzer_error, Msg}` clause for the `check_output_plt` path. Split `start/0` into a thin wrapper over `start/1` (which takes the argument list) so the parsing path is testable without spawning a node; `start/1` is exported but marked `-doc false` as it is not part of the public API.

Add `dialyzer_cl_SUITE:bad_pa_dir_returns_error/1`, which drives `start/1` with a non-existent `-pa` directory and asserts a clean `{error, _}` return.
@kikofernandez kikofernandez self-assigned this Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

CT Test Results

  2 files   42 suites   15m 57s ⏱️
486 tests 482 ✅ 4 💤 0 ❌
574 runs  570 ✅ 4 💤 0 ❌

Results for commit 63d9cfe.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

garazdawi
garazdawi previously approved these changes Sep 22, 2026
@kikofernandez kikofernandez added the testing currently being tested, tag is used by OTP internal CI label Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants