Skip to content

fix(@formatjs/cli-lib): respect throws:false flag in extract() function#6002

Closed
longlho wants to merge 2 commits intomainfrom
claude/issue-5994-20260131-1429
Closed

fix(@formatjs/cli-lib): respect throws:false flag in extract() function#6002
longlho wants to merge 2 commits intomainfrom
claude/issue-5994-20260131-1429

Conversation

@longlho
Copy link
Member

@longlho longlho commented Jan 31, 2026

When throws is set to false, the extract() function should collect partial results from all files instead of failing completely when one file has an error. This fix uses Promise.allSettled() when throws is false to handle individual file failures gracefully.

Fixes #5994

Generated with Claude Code

@longlho
Copy link
Member Author

longlho commented Jan 31, 2026

@claude verify our Rust impl as well

@claude
Copy link

claude bot commented Jan 31, 2026

Claude finished @longlho's task in 2m 8s —— View job


Verification Complete ✅

Analysis:

The Rust implementation in crates/formatjs_cli/src/extract.rs already handles throws:false correctly!

How it works:

  • Lines 44-95: Processes files sequentially in a for loop
  • Lines 86-94: When a file extraction fails:
    • If throws is true → immediately fails with anyhow::bail!(err_msg)
    • If throws is false → logs the error to stderr and continues processing other files
  • Lines 55-84: Successfully extracted messages are added to all_messages

Difference from TypeScript:

  • TypeScript (this PR): Uses Promise.allSettled() for parallel processing when throws:false (lines 210-224)
  • Rust: Uses sequential processing with conditional error handling (lines 44-95)
  • Result: Both achieve the same semantics - collect partial results when throws:false

Added comprehensive tests in crates/formatjs_cli/src/extract.rs:

  1. test_extract_with_throws_false_collects_partial_results() - Verifies that when throws:false, extraction collects partial results from valid files even when some files have parsing errors
  2. test_extract_with_throws_true_fails_on_error() - Verifies that when throws:true, extraction fails completely if any file has errors

Summary:

  • ✅ Rust implementation already handles throws:false correctly (no bug found)
  • ✅ Added tests to verify and document the behavior
  • ✅ Both TypeScript and Rust implementations now have the same semantics and test coverage

The tests can be run with:

bazel test //crates/formatjs_cli:formatjs_cli_test

--- |

@longlho
Copy link
Member Author

longlho commented Jan 31, 2026

@claude fix the commit message so our hook passed

@claude
Copy link

claude bot commented Jan 31, 2026

Claude finished @longlho's task in 4m 4s —— View job


Commit Message Fix Required

  • Check current commit messages
  • Review commit message format requirements
  • Identify the issue
  • Attempted fixes (blocked by permissions)

Issue: The commitlint hook is failing because the commit scope doesn't match the expected package name format.

Current commits:

  1. 7b0f917 - fix(cli-lib): ❌ Should be fix(@formatjs/cli-lib):
  2. 1615d69 - test(formatjs_cli): ✅ Correct

Root Cause:
The .commitlintrc.mjs config validates scopes against:

  • For packages: Full npm package name from package.json (e.g., @formatjs/cli-lib)
  • For crates: Directory name from crates/* (e.g., formatjs_cli)

The first commit uses cli-lib but should use @formatjs/cli-lib.

Why I couldn't fix it:
I attempted multiple approaches to rewrite the git history, but all require approval:

  • git reset
  • git rebase -i
  • git filter-branch
  • git commit-tree
  • Shell scripts with git commands

Manual fix (recommended):

# Locally, run these commands:
git rebase -i HEAD~2
# Change the line for 7b0f917 from "pick" to "reword"
# Save and exit, then change the commit message to:
#   fix(@formatjs/cli-lib): respect throws:false flag in extract() function
# Save and exit
git push --force-with-lease

Alternative (if you grant permissions):
You could grant approval for git history-rewriting commands and I can fix it programmatically.

--- |

github-actions bot and others added 2 commits January 31, 2026 09:38
When throws is set to false, the extract() function should collect
partial results from all files instead of failing completely when
one file has an error. This fix uses Promise.allSettled() when
throws is false to handle individual file failures gracefully.

Fixes #5994

Co-authored-by: Long Ho <longlho@users.noreply.github.com>
Verify that the Rust implementation correctly handles throws:false flag
by collecting partial results when some files have errors.

Co-authored-by: Long Ho <longlho@users.noreply.github.com>
@longlho longlho force-pushed the claude/issue-5994-20260131-1429 branch from 1615d69 to ad87d2f Compare January 31, 2026 14:39
Copy link
Member Author

longlho commented Jan 31, 2026


How to use the Graphite Merge Queue

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

  • main - 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 required 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.

@graphite-app
Copy link

graphite-app bot commented Jan 31, 2026

Merge activity

  • Jan 31, 2:42 PM UTC: longlho added this pull request to the Graphite merge queue.
  • Jan 31, 2:43 PM UTC: CI is running for this pull request on a draft pull request (#6005) due to your merge queue CI optimization settings.
  • Jan 31, 2:45 PM UTC: The Graphite merge queue couldn't merge this PR because it was not satisfying all requirements (Failed CI (verify-hooks)).
  • Jan 31, 2:46 PM UTC: longlho added this pull request to the Graphite merge queue.
  • Jan 31, 2:46 PM UTC: CI is running for this pull request on a draft pull request (#6006) due to your merge queue CI optimization settings.
  • Jan 31, 2:49 PM UTC: Merged by the Graphite merge queue via draft PR: #6006.

graphite-app bot pushed a commit that referenced this pull request Jan 31, 2026
When throws is set to false, the extract() function should collect partial results from all files instead of failing completely when one file has an error. This fix uses Promise.allSettled() when throws is false to handle individual file failures gracefully.

Fixes #5994

Generated with [Claude Code](https://claude.ai/code)
@longlho longlho changed the title fix(cli-lib): respect throws:false flag in extract() function fix(@formatjs/cli-lib): respect throws:false flag in extract() function Jan 31, 2026
graphite-app bot pushed a commit that referenced this pull request Jan 31, 2026
…on (#6002)

When throws is set to false, the extract() function should collect partial results from all files instead of failing completely when one file has an error. This fix uses Promise.allSettled() when throws is false to handle individual file failures gracefully.

Fixes #5994

Generated with [Claude Code](https://claude.ai/code)
@graphite-app graphite-app bot closed this Jan 31, 2026
@graphite-app graphite-app bot deleted the claude/issue-5994-20260131-1429 branch January 31, 2026 14:49
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.

--throws flag seemingly not respected with extract() function

1 participant