Skip to content

fix: Avoids duplicated error when running dev - #3201

Merged
hellofanny merged 2 commits into
feat/multilanguagefrom
chore/build-localization-cli-error
Feb 6, 2026
Merged

hellofanny merged 2 commits into
feat/multilanguagefrom
chore/build-localization-cli-error

Conversation

@hellofanny

@hellofanny hellofanny commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

Avoids duplicated log error message when running yarn dev:

Before After
image image

How it works?

How to test it?

Starters Deploy Preview

Summary by CodeRabbit

  • Refactor
    • Improved internal configuration handling in CLI build and development commands for more consistent localization settings management.

@coderabbitai

coderabbitai Bot commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

This 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

Cohort / File(s) Summary
CLI Command Handlers
packages/cli/src/commands/build.ts, packages/cli/src/commands/dev.ts
Replaced checkAndValidateLocalization import and logic with getDiscoveryConfig. Now determines localization enablement via config?.localization?.enabled === true instead of dedicated validator. Updated comments to reflect that generate-i18n handles validation.
Config Utilities
packages/cli/src/utils/config.ts
Exported getDiscoveryConfig function as public API to support centralized config retrieval across CLI commands.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • lariciamota
  • lemagnetic

Poem

Config once scattered, now takes flight,
A single getter sets things right,
Build and dev in harmony,
Localization flows so free! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing checkAndValidateLocalization with getDiscoveryConfig to prevent duplicate error messages when running dev.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/build-localization-cli-error

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codesandbox-ci

codesandbox-ci Bot commented Feb 5, 2026 •

Copy link
Copy Markdown

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.

@hellofanny
hellofanny marked this pull request as ready for review February 6, 2026 19:58
@hellofanny
hellofanny requested a review from a team as a code owner February 6, 2026 19:58
@hellofanny
hellofanny requested review from eduardoformiga and lucasfp13 and removed request for a team February 6, 2026 19:58

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +206 to 214
// 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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.

Suggested change
// 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 eduardoformiga 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.

Are we still using checkAndValidateLocalization elsewhere? If not, I'd remove it.

@hellofanny

Copy link
Copy Markdown
Contributor Author

checkAndValidateLocalization

yes, still using in generate-i18n.ts

@hellofanny hellofanny self-assigned this Feb 6, 2026
@hellofanny
hellofanny merged commit 94aa20f into feat/multilanguage Feb 6, 2026
2 checks passed
@hellofanny
hellofanny deleted the chore/build-localization-cli-error branch February 6, 2026 20:23
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