Skip to content

analysis: fix namespace parsing after Yojson migration#8454

Merged
fhammerschmidt merged 4 commits into
masterfrom
analyisis-namespace-parsing
May 31, 2026
Merged

analysis: fix namespace parsing after Yojson migration#8454
fhammerschmidt merged 4 commits into
masterfrom
analyisis-namespace-parsing

Conversation

@fhammerschmidt
Copy link
Copy Markdown
Member

@fhammerschmidt fhammerschmidt commented May 31, 2026

@aspeddro

Problem

The Yojson migration changed analysis config parsing in a subtle way. The code
used Yojson.Safe.Util.to_string_option and to_bool_option as if they were
non-throwing type probes, but Yojson's _option helpers only return None for
null; they still raise Type_error for other mismatched JSON types.

That broke valid namespace configs such as:

{ "namespace": "my-namespace" }

because analysis first tried to decode namespace as a string, then also tried
to decode it as a bool. The second probe raised instead of returning None.
The opposite shape, { "namespace": true }, had the same problem in reverse.

Fix

Parse namespace once into a closed OCaml variant:

type namespace_config =
  | NamespaceDisabled
  | NamespaceFromPackageName
  | NamespaceExplicit of string

Then derive the existing string option from that typed representation. This
makes the bool/string/absent cases exhaustive and prevents later code from
probing the same raw JSON value as multiple incompatible types.

The patch also adds shared non-throwing Yojson helpers for config-style reads
and replaces the remaining unsafe Yojson option extractors in analysis and
reanalyze's .sourcedirs.json scan-plan parsing.

Coverage

Added OUnit coverage for namespace config parsing:

  • absent namespace
  • namespace: false
  • invalid non-string/non-bool values
  • namespace: true
  • explicit string namespace

@fhammerschmidt fhammerschmidt requested a review from cknitt May 31, 2026 07:28
@codecov
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

Codecov Report

❌ Patch coverage is 91.37931% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.68%. Comparing base (f390dfc) to head (32f0ddb).

Files with missing lines Patch % Lines
analysis/src/FindFiles.ml 75.00% 4 Missing ⚠️
tests/ounit_tests/ounit_analysis_config_tests.ml 97.56% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8454      +/-   ##
==========================================
+ Coverage   60.63%   60.68%   +0.04%     
==========================================
  Files         373      373              
  Lines       54057    54095      +38     
==========================================
+ Hits        32778    32826      +48     
+ Misses      21279    21269      -10     
Files with missing lines Coverage Δ
analysis/src/Packages.ml 55.14% <100.00%> (ø)
tests/ounit_tests/ounit_tests_main.ml 100.00% <ø> (ø)
tests/ounit_tests/ounit_analysis_config_tests.ml 97.56% <97.56%> (ø)
analysis/src/FindFiles.ml 58.20% <75.00%> (+4.72%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 31, 2026

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8454

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8454

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8454

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8454

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8454

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8454

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8454

commit: 32f0ddb

@github-actions
Copy link
Copy Markdown

@cknitt
Copy link
Copy Markdown
Member

cknitt commented May 31, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@aspeddro
Copy link
Copy Markdown
Contributor

Thank you to fix it @fhammerschmidt

@fhammerschmidt fhammerschmidt merged commit f0636e0 into master May 31, 2026
30 checks passed
@fhammerschmidt fhammerschmidt deleted the analyisis-namespace-parsing branch May 31, 2026 12:05
aspeddro added a commit to aspeddro/rescript-compiler that referenced this pull request May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants