Skip to content

fix(various): unwrap Result of write! macro#10228

Merged
graphite-app[bot] merged 1 commit intomainfrom
04-04-fix_various_unwrap_result_of_write_macro
Apr 4, 2025
Merged

fix(various): unwrap Result of write! macro#10228
graphite-app[bot] merged 1 commit intomainfrom
04-04-fix_various_unwrap_result_of_write_macro

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Apr 4, 2025

#10196 replaced the anti-pattern of str.push_str(&format!("...")); with let _ = write!(str, "...");.

However, this ignores the Result returned by write! macro. It's unspecified what happens when the String reaches capacity - it may return Result::Err, or may panic. Ensure we get a panic, rather than silently generating incorrect output by calling unwrap() on the Result.

This problem could never arise in practice on 64-bit systems because max capacity of String is enormous, but it's not impossible on 32-bit systems (e.g. WASM).

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-transformer Area - Transformer / Transpiler A-isolated-declarations Isolated Declarations A-editor Area - Editor and Language Server A-formatter Area - Formatter C-bug Category - Bug labels Apr 4, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@overlookmotel overlookmotel marked this pull request as ready for review April 4, 2025 14:29
@overlookmotel overlookmotel requested a review from Dunqing as a code owner April 4, 2025 14:29
@overlookmotel overlookmotel requested review from Boshen and removed request for Dunqing April 4, 2025 14:30
@codspeed-hq
Copy link

codspeed-hq bot commented Apr 4, 2025

CodSpeed Instrumentation Performance Report

Merging #10228 will degrade performances by 3.5%

Comparing 04-04-fix_various_unwrap_result_of_write_macro (d691701) with main (dab1bd8)

Summary

⚡ 1 improvements
❌ 1 regressions
✅ 34 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
formatter[antd.js] 7.6 ms 7.9 ms -3.5%
formatter[typescript.js] 7.6 ms 7.2 ms +5.44%

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Apr 4, 2025
Copy link
Member

Boshen commented Apr 4, 2025

Merge activity

#10196 replaced the anti-pattern of `str.push_str(&format!("..."));` with `let _ = write!(str, "...");`.

However, this ignores the `Result` returned by `write!` macro. It's unspecified what happens when the `String` reaches capacity - it may return `Result::Err`, or may panic. Ensure we get a panic, rather than silently generating incorrect output by calling `unwrap()` on the `Result`.

This problem could never arise in practice on 64-bit systems because max capacity of `String` is enormous, but it's not impossible on 32-bit systems (e.g. WASM).
@graphite-app graphite-app bot force-pushed the 04-04-fix_various_unwrap_result_of_write_macro branch from a0b64f3 to d691701 Compare April 4, 2025 14:38
@graphite-app graphite-app bot merged commit d691701 into main Apr 4, 2025
30 checks passed
@graphite-app graphite-app bot deleted the 04-04-fix_various_unwrap_result_of_write_macro branch April 4, 2025 14:44
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Apr 4, 2025
This was referenced Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-editor Area - Editor and Language Server A-formatter Area - Formatter A-isolated-declarations Isolated Declarations A-linter Area - Linter A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants