Repository navigation
fix: Avoids duplicated error when running dev - #3201
Conversation
WalkthroughThis PR refactors localization configuration handling in CLI commands by replacing direct validator calls with a centralized config getter function, consolidating how localization enablement is determined across build and dev commands. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
…uild-localization-cli-error
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/cli/src/commands/dev.ts`:
- Around line 206-214: The spawnSync call that runs `node ${cliPath}
generate-i18n` in dev.ts currently discards its result; capture it (e.g., let
scriptResult = spawnSync(...)) and mirror the failure handling used in build.ts
by checking scriptResult.status (or scriptResult.error) after the call and
throwing/terminating when it indicates failure so the dev server does not
continue with an invalid localization config; keep the subsequent calls to
getDiscoveryConfig(basePath) and toggleMiddlewareByLocalizationFlag(basePath,
localizationEnabled) only after the spawn result is verified.
| // generate-i18n will validate localization config and check if it's enabled | ||
| spawnSync(`node ${cliPath} generate-i18n`, { | ||
| shell: true, | ||
| stdio: 'inherit', | ||
| }) | ||
|
|
||
| const localizationEnabled = await checkAndValidateLocalization(basePath) | ||
| const config = await getDiscoveryConfig(basePath) | ||
| const localizationEnabled = config?.localization?.enabled === true | ||
| toggleMiddlewareByLocalizationFlag(basePath, localizationEnabled) |
There was a problem hiding this comment.
Missing error check on generate-i18n spawn result.
In build.ts (lines 91–96), the result of spawnSync('generate-i18n') is checked and throws on failure. Here in dev.ts, the result is discarded. Since validation of the localization config now lives inside generate-i18n, a failed validation won't stop the dev server — it'll keep running with a broken config.
Proposed fix
// generate-i18n will validate localization config and check if it's enabled
- spawnSync(`node ${cliPath} generate-i18n`, {
+ scriptResult = spawnSync(`node ${cliPath} generate-i18n`, {
shell: true,
stdio: 'inherit',
})
+
+ if (scriptResult.error || scriptResult.status !== 0) {
+ throw new Error(
+ 'Error: Unable to run generate-i18n' +
+ (scriptResult.error?.message ?? '')
+ )
+ }You'll need to declare let scriptResult (or a local variable) to capture the result, similar to how build.ts does it.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // generate-i18n will validate localization config and check if it's enabled | |
| spawnSync(`node ${cliPath} generate-i18n`, { | |
| shell: true, | |
| stdio: 'inherit', | |
| }) | |
| const localizationEnabled = await checkAndValidateLocalization(basePath) | |
| const config = await getDiscoveryConfig(basePath) | |
| const localizationEnabled = config?.localization?.enabled === true | |
| toggleMiddlewareByLocalizationFlag(basePath, localizationEnabled) | |
| // generate-i18n will validate localization config and check if it's enabled | |
| scriptResult = spawnSync(`node ${cliPath} generate-i18n`, { | |
| shell: true, | |
| stdio: 'inherit', | |
| }) | |
| if (scriptResult.error || scriptResult.status !== 0) { | |
| throw new Error( | |
| 'Error: Unable to run generate-i18n' + | |
| (scriptResult.error?.message ?? '') | |
| ) | |
| } | |
| const config = await getDiscoveryConfig(basePath) | |
| const localizationEnabled = config?.localization?.enabled === true | |
| toggleMiddlewareByLocalizationFlag(basePath, localizationEnabled) |
🤖 Prompt for AI Agents
In `@packages/cli/src/commands/dev.ts` around lines 206 - 214, The spawnSync call
that runs `node ${cliPath} generate-i18n` in dev.ts currently discards its
result; capture it (e.g., let scriptResult = spawnSync(...)) and mirror the
failure handling used in build.ts by checking scriptResult.status (or
scriptResult.error) after the call and throwing/terminating when it indicates
failure so the dev server does not continue with an invalid localization config;
keep the subsequent calls to getDiscoveryConfig(basePath) and
toggleMiddlewareByLocalizationFlag(basePath, localizationEnabled) only after the
spawn result is verified.
eduardoformiga
left a comment
There was a problem hiding this comment.
Are we still using checkAndValidateLocalization elsewhere? If not, I'd remove it.
yes, still using in |
What's the purpose of this pull request?
Avoids duplicated log error message when running
yarn dev:How it works?
How to test it?
Starters Deploy Preview
Summary by CodeRabbit