refactor: extract storage error hints#170
refactor: extract storage error hints#170ndycode wants to merge 6 commits intorefactor/pr2-statusline-settings-split-2from
Conversation
📝 WalkthroughWalkthroughA new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Issues flaggedmissing regression tests: test case only covers EBUSY. what about coverage for EACCES, EPERM, ENOSPC, EEMPTY, and the "UNKNOWN" fallback at windows edge cases: errno codes differ on windows (e.g., EACCES maps differently). verify that concurrency risks: Suggested labels
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
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 |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/storage/error-hints.ts`:
- Around line 27-41: Extract the duplicated code that reads err?.code ||
"UNKNOWN" into a small helper named extractErrorCode(error: unknown): string,
implement it to cast to NodeJS.ErrnoException and return the code or "UNKNOWN",
then replace the inline duplication in toStorageError and the similar logic in
formatStorageErrorHint (or any other occurrences) to call
extractErrorCode(error) so the error-code extraction is centralized and DRY.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 84d89c77-3b3d-4369-8628-b23f7c2994a0
📒 Files selected for processing (4)
lib/errors.tslib/storage.tslib/storage/error-hints.tstest/storage.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Greptile Review
🧰 Additional context used
📓 Path-based instructions (2)
test/**
⚙️ CodeRabbit configuration file
tests must stay deterministic and use vitest. demand regression cases that reproduce concurrency bugs, token refresh races, and windows filesystem behavior. reject changes that mock real secrets or skip assertions.
Files:
test/storage.test.ts
lib/**
⚙️ CodeRabbit configuration file
focus on auth rotation, windows filesystem IO, and concurrency. verify every change cites affected tests (vitest) and that new queues handle EBUSY/429 scenarios. check for logging that leaks tokens or emails.
Files:
lib/errors.tslib/storage/error-hints.tslib/storage.ts
🔇 Additional comments (9)
test/storage.test.ts (2)
30-30: direct import from internal module is fine here, but note it's not re-exported from the barrel.
toStorageErroris imported fromlib/storage/error-hints.jsdirectly whileformatStorageErrorHintcomes from the barrel atlib/storage.js:19. iftoStorageErroris intended as internal-only, this is correct. if it should be public api, consider re-exporting it fromlib/storage.ts.
82-96: lgtm. good coverage for ebusy/windows file lock scenario.test validates
toStorageErrorwraps the cause correctly and preserves error metadata. this aligns with the concurrency/windows filesystem requirements inlib/storage.tsretry paths.lib/errors.ts (1)
167-189: lgtm. storageerror follows the same pattern as other error classes in this file.error chaining via
{ cause }is correct. readonly properties prevent accidental mutation. no sensitive data (tokens/emails) stored in the error structure.lib/storage/error-hints.ts (2)
1-1: circular dependency correctly broken by importing fromerrors.jsinstead ofstorage.js.the pr description flagged a cycle between
error-hints.ts → storage.ts → error-hints.ts. importingStorageErrorfromlib/errors.ts:171avoids that issue.
3-25: lgtm. platform-aware error hints with ebusy handling.ebusy at
lib/storage/error-hints.ts:14-15provides actionable guidance for windows file lock scenarios. no tokens or emails leak into the hint strings.lib/storage.ts (4)
6-6: lgtm. re-exports maintain public api surface after extraction.
StorageErrorandformatStorageErrorHintare re-exported so existing consumers importing fromlib/storage.tsare unaffected.toStorageErroris intentionally not re-exported, keeping it internal to the error-hints module.Also applies to: 15-19
132-199: formatting changes only. no logic changes detected.these are log.debug formatting adjustments. verified no tokens or emails appear in the logged fields (
candidatePath,fileName,mtime,error.message,error.stack).
1300-1303: minor formatting tweak in selectnewestaccount call.no logic change.
matchingAccount ?? undefinedis redundant sincematchingAccountis alreadyT | null, but the explicit fallback doesn't hurt.
2087-2089: formatting only. transaction rollback logic unchanged.verified the account storage rollback path at
lib/storage.ts:2096-2113still handles flagged save failures correctly with aggregate error wrapping.
Summary
lib/storage.tsinto a dedicated helper moduleStorageErrorand storage-save behavior intact while starting the storage split in a small low-risk sliceWhat Changed
lib/storage/error-hints.tswithformatStorageErrorHint(...)lib/storage.tsto import and re-export the helper so the existing public surface stays intacttest/storage.test.tsto import the helper from its new module while still exercising the same behavior expectationsValidation
npm run test -- test/storage.test.tsnpm run lintnpm run typechecknpm run buildRisk and Rollback
aa77ab7to restore the inline storage error-hint implementationAdditional Notes
note: greptile review for oc-chatgpt-multi-auth. cite files like
lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.Greptile Summary
this PR completes a clean, low-risk slice of the storage split:
StorageErroris moved intolib/errors.ts(now correctly extendingCodexError), error-hint logic is extracted intolib/storage/error-hints.ts, and the circular dependency from the previous iteration is fully resolved. thetoStorageErrorfactory is now wired into thesaveAccountsUnlockedcall site, eliminating the dead-code concern from the last review.key changes:
StorageErrornow extendsCodexError— upstreaminstanceof CodexErrorcatches will no longer silently miss storage failureserror-hints↔storage) eliminated — both files now importStorageErrorfromerrors.tsdirectlyEEMPTY(not a real POSIX code) removed from the switch and its test deletedENOENThint added — correct guidance for missing parent directory, though the hint is not yet Windows-aware (unlike every other platform-sensitive branch) and has no vitest test coverage for the new branchConfidence Score: 4/5
Important Files Changed
StorageErrorcorrectly moved here and now extendsCodexError— hierarchy fix complete,codefield inherited,pathandhintadded as own properties.ENOENTbranch added but hint is not Windows-aware (missing platform split), and the branch has no vitest test coverage.saveAccountsUnlockedcorrectly usestoStorageError; re-exportsStorageErrorandformatStorageErrorHintfrom their new canonical locations; formatting-only changes elsewhere are clean.toStorageErrortest added andEEMPTYtest correctly removed;ENOENThint branch added in production but not tested here.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[saveAccountsUnlocked] -->|catch error| B[toStorageError] B --> C[extractErrorCode] B --> D[formatStorageErrorHint] C -->|errno string| D D -->|switch on code| E{code?} E -->|EACCES / EPERM| F[Windows: antivirus hint\nUnix: chmod hint] E -->|EBUSY| G[file-lock hint] E -->|ENOENT| H[missing-path hint\n⚠️ not Windows-aware] E -->|ENOSPC| I[disk-full hint] E -->|default| J[Windows: special-chars hint\nUnix: permissions hint] D -->|hint string| B B -->|StorageError| A A -->|throw StorageError| K[caller] subgraph errors.ts L[CodexError] --> M[StorageError] end B -.->|new StorageError| MComments Outside Diff (1)
test/storage.test.ts, line 14-30 (link)formatStorageErrorHintimportformatStorageErrorHintis imported twice in the same scope: once via the../lib/storage.jsbarrel (line 14) and again directly from../lib/storage/error-hints.js(line 30). TypeScript will surface this as a duplicate identifier error and the file won't compile.remove the redundant import on line 30 — the barrel re-export on line 14 already gives you the same value:
actually, drop line 14's
formatStorageErrorHintfrom the barrel import and keep only the direct import on line 30, or vice versa. e.g.:Prompt To Fix With AI
Prompt To Fix All With AI
Last reviewed commit: "docs: describe stora..."