Skip to content

Fix build crash when compiler output is not valid UTF-8#8482

Open
nathan-tranquilla wants to merge 3 commits into
rescript-lang:masterfrom
nathan-tranquilla:fix-non-utf8-compiler-output-panic
Open

Fix build crash when compiler output is not valid UTF-8#8482
nathan-tranquilla wants to merge 3 commits into
rescript-lang:masterfrom
nathan-tranquilla:fix-non-utf8-compiler-output-panic

Conversation

@nathan-tranquilla

@nathan-tranquilla nathan-tranquilla commented Jun 21, 2026

Copy link
Copy Markdown

We ran into this panic in CI on a production app we're building with ReScript. The Ok branch in compile.rs decodes bsc's captured stderr with from_utf8().expect(), which crashes the whole build when that output is not valid UTF-8, while the two branches right above it already use from_utf8_lossy. bsc does produce invalid UTF-8 when a styled code frame cuts a multi-byte character mid-byte: compiling a line with an em dash, we captured a lone e2 (the first byte of U+2014) followed immediately by an ANSI escape. This switches that branch to from_utf8_lossy too; the first commit adds a unit test that reproduces the panic and the second applies the fix.

bsc can print a code frame that cuts a multi-byte character in half, so the
captured stderr is not always valid utf-8. The Ok branch decodes it with
from_utf8().expect(), which panics and takes down the whole build with a byte
offset into stdout and no file name. This test feeds a truncated em dash and
reproduces the panic.
The Ok branch used from_utf8().expect() on the captured stderr, which panics
when the output is not valid utf-8. The two sibling branches right above it
already use from_utf8_lossy. Use it here too so a truncated character turns into
a replacement character and the build keeps going instead of crashing.
@fhammerschmidt

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: f62e9ff9aa

ℹ️ 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".

@fhammerschmidt fhammerschmidt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for reporting and fixing.

@fhammerschmidt fhammerschmidt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah yes, would you add a Changelog entry, please?

@pkg-pr-new

pkg-pr-new Bot commented Jun 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: f62e9ff

@nathan-tranquilla

Copy link
Copy Markdown
Author

Addressed, thanks!

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.

2 participants