Skip to content

refactor: change key of symbols and bump routup to v5.0.0-beta.4#772

Merged
tada5hi merged 4 commits intomasterfrom
plugin-error
Apr 10, 2026
Merged

refactor: change key of symbols and bump routup to v5.0.0-beta.4#772
tada5hi merged 4 commits intomasterfrom
plugin-error

Conversation

@tada5hi
Copy link
Copy Markdown
Contributor

@tada5hi tada5hi commented Apr 10, 2026

Summary by CodeRabbit

  • Chores
    • Updated routup peer dependency to ^5.0.0-beta.4 across packages and added an explicit routup peer dependency at the repository root.
  • Bug Fixes
    • Plugins now validate installation and surface descriptive errors when used without initialization instead of returning empty defaults or undefined.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

The PR bumps routup peer/dev dependency to ^5.0.0-beta.4, migrates multiple plugin keys from Symbol.for(...) to Symbol(...) (making them module-local), and replaces silent fallbacks with explicit PluginNotInstalledError checks when plugin-specific state is missing.

Changes

Cohort / File(s) Summary
Root / Top-level
package.json
Added top-level peerDependencies with routup: ^5.0.0-beta.4.
Dependency Version Updates
packages/assets/package.json, packages/basic/package.json, packages/body/package.json, packages/cookie/package.json, packages/decorators/package.json, packages/i18n/package.json, packages/prometheus/package.json, packages/query/package.json, packages/rate-limit-redis/package.json, packages/rate-limit/package.json, packages/swagger/package.json
Updated routup version from ^5.0.0-beta.3^5.0.0-beta.4 in peerDependencies and devDependencies.
Symbol Migration: Constants / Metadata
packages/body/src/constants.ts, packages/i18n/src/constants.ts, packages/decorators/src/utils/meta.ts
Replaced global Symbol.for(...) with module-local Symbol(...) for exported keys (options/body/raw-body, i18n request symbols, decorator meta).
Symbol Migration & Behavior Changes: Request Helpers
packages/cookie/src/request.ts, packages/query/src/request.ts, packages/rate-limit/src/request.ts
Switched from Symbol.for(...)Symbol(...) for request-store keys and changed read helpers: they now validate presence and (in some cases) throw PluginNotInstalledError instead of returning defaults.
Body: read helper & tests
packages/body/src/helpers/read.ts, packages/body/test/unit/module.spec.ts
readRequestBody now checks for plugin installation and throws PluginNotInstalledError when missing; test updated to expect a 500 error for missing plugin.
i18n: translator helper
packages/i18n/src/use-translator.ts
Replaced custom error creation with throwing PluginNotInstalledError when i18n instance is missing (symbol migration applied).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 I hopped through symbols, soft and light,
Each module now guards its secret bright.
No quiet blanks when plugins are gone,
A stern little error to carry on. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the two main changes: converting global symbols to local symbols and upgrading the routup peer dependency to v5.0.0-beta.4.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch plugin-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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
packages/body/test/unit/module.spec.ts (1)

149-149: Assert error identity, not only HTTP 500.

This currently passes for any internal error. Add an assertion that verifies the response/error corresponds to PluginNotInstalledError for stronger regression coverage.

Suggested test hardening
         expect(response.status).toEqual(500);
+        const text = await response.text();
+        expect(text).toContain('PluginNotInstalledError');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/body/test/unit/module.spec.ts` at line 149, The test currently only
asserts expect(response.status).toEqual(500) which is too broad; update the test
in module.spec.ts to also assert the error identity for PluginNotInstalledError
by either importing PluginNotInstalledError and asserting the returned error is
an instance of it (e.g.,
expect(response.body.error).toBeInstanceOf(PluginNotInstalledError)) or by
asserting the error name/code in the response payload (e.g.,
expect(response.body.error.name).toEqual('PluginNotInstalledError') or
expect(response.body.error.code).toEqual('PluginNotInstalledError')), keeping
the existing status assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/cookie/src/request.ts`:
- Line 5: Replace the package-local symbol with a global symbol so the cookie
store key is identical across module instances: change the CookieSymbol
declaration used by createHandler() and useRequestCookies() from
Symbol('ReqCookie') to a Symbol.for(...) call (e.g., Symbol.for('ReqCookie') or
another stable key string) so PluginNotInstalledError checks reference the same
symbol instance across duplicate dependency graphs.

In `@packages/decorators/src/utils/meta.ts`:
- Line 3: Replace the instance-local symbol with a globally-registered symbol so
metadata is shared across package instances: in the file where the const symbol
= Symbol('DecoratorMeta') is declared (the symbol variable used for decorator
metadata lookup), change it to use Symbol.for('DecoratorMeta') so the symbol is
resolved from the global symbol registry and metadata attached by one bundle is
visible to other bundles.

In `@packages/i18n/src/constants.ts`:
- Around line 1-2: The request-store symbols are currently created with
Symbol(...) so different installed/bundled copies can produce different
identities; replace their creation to use Symbol.for('ReqI18nInstance') and
Symbol.for('ReqI18nLocale') instead so the symbols are registered in the global
symbol registry and shared across module instances (update the declarations for
REQUEST_INSTANCE_SYMBOL and REQUEST_LOCALE_SYMBOL accordingly).

In `@packages/rate-limit/src/request.ts`:
- Line 6: The module creates RateLimitSymbol with Symbol() which is module-local
and can differ across bundled/duplicated instances causing
useRequestRateLimitInfo/setRequestRateLimitInfo to miss the stored value and
throw PluginNotInstalledError; change the declaration of RateLimitSymbol to use
Symbol.for('ReqRateLimit') so the symbol is global across module instances, keep
the same identifier RateLimitSymbol and ensure setRequestRateLimitInfo and
useRequestRateLimitInfo continue to read/write using that symbol.

---

Nitpick comments:
In `@packages/body/test/unit/module.spec.ts`:
- Line 149: The test currently only asserts expect(response.status).toEqual(500)
which is too broad; update the test in module.spec.ts to also assert the error
identity for PluginNotInstalledError by either importing PluginNotInstalledError
and asserting the returned error is an instance of it (e.g.,
expect(response.body.error).toBeInstanceOf(PluginNotInstalledError)) or by
asserting the error name/code in the response payload (e.g.,
expect(response.body.error.name).toEqual('PluginNotInstalledError') or
expect(response.body.error.code).toEqual('PluginNotInstalledError')), keeping
the existing status assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 33d30f8c-2a35-49d5-bc5a-f3a5f0c5a068

📥 Commits

Reviewing files that changed from the base of the PR and between 285d6ce and 014b3f7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (21)
  • package.json
  • packages/assets/package.json
  • packages/basic/package.json
  • packages/body/package.json
  • packages/body/src/constants.ts
  • packages/body/src/helpers/read.ts
  • packages/body/test/unit/module.spec.ts
  • packages/cookie/package.json
  • packages/cookie/src/request.ts
  • packages/decorators/package.json
  • packages/decorators/src/utils/meta.ts
  • packages/i18n/package.json
  • packages/i18n/src/constants.ts
  • packages/i18n/src/use-translator.ts
  • packages/prometheus/package.json
  • packages/query/package.json
  • packages/query/src/request.ts
  • packages/rate-limit-redis/package.json
  • packages/rate-limit/package.json
  • packages/rate-limit/src/request.ts
  • packages/swagger/package.json

Comment thread packages/cookie/src/request.ts Outdated
Comment thread packages/decorators/src/utils/meta.ts Outdated
Comment thread packages/i18n/src/constants.ts Outdated
Comment thread packages/rate-limit/src/request.ts Outdated
@tada5hi tada5hi changed the title feat: throw PluginNotInstalledError for store-dependent helpers refactor: use private symbols for store keys and bump routup to v5.0.0-beta.4 Apr 10, 2026
@tada5hi tada5hi changed the title refactor: use private symbols for store keys and bump routup to v5.0.0-beta.4 refactor: change key of symbols and bump routup to v5.0.0-beta.4 Apr 10, 2026
@tada5hi tada5hi merged commit a3c17c5 into master Apr 10, 2026
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.

1 participant