-
Notifications
You must be signed in to change notification settings - Fork 2
refactor: extract storage error hints #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ndycode
wants to merge
6
commits into
refactor/pr2-statusline-settings-split-2
from
refactor/pr3-storage-error-helpers
+141
−93
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aa77ab7
refactor: extract storage error hints
ndycode a7b3cfb
fix: break storage error helper cycle
ndycode e01437e
fix: align storage error review followups
ndycode 8f18512
fix: reuse storage error factory in save path
ndycode 2412b22
fix: add missing storage ENOENT hint
ndycode e0ee884
docs: describe storage error helpers
ndycode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { StorageError } from "../errors.js"; | ||
|
|
||
| function extractErrorCode(error: unknown): string { | ||
| const err = error as NodeJS.ErrnoException; | ||
| return err?.code || "UNKNOWN"; | ||
| } | ||
|
|
||
| /** | ||
| * Format a user-facing hint for storage persistence failures based on errno code. | ||
| */ | ||
| export function formatStorageErrorHint(error: unknown, path: string): string { | ||
| const code = extractErrorCode(error); | ||
| const isWindows = process.platform === "win32"; | ||
|
|
||
| switch (code) { | ||
| case "EACCES": | ||
| case "EPERM": | ||
| return isWindows | ||
| ? `Permission denied writing to ${path}. Check antivirus exclusions for this folder. Ensure you have write permissions.` | ||
| : `Permission denied writing to ${path}. Check folder permissions. Try: chmod 755 ~/.codex`; | ||
| case "EBUSY": | ||
| return `File is locked at ${path}. The file may be open in another program. Close any editors or processes accessing it.`; | ||
| case "ENOENT": | ||
| return `Path does not exist: ${path}. Create the parent folder and try again.`; | ||
| case "ENOSPC": | ||
| return `Disk is full. Free up space and try again. Path: ${path}`; | ||
| default: | ||
| return isWindows | ||
| ? `Failed to write to ${path}. Check folder permissions and ensure path contains no special characters.` | ||
| : `Failed to write to ${path}. Check folder permissions and disk space.`; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Wrap an arbitrary storage failure in a StorageError with a derived hint. | ||
| */ | ||
| export function toStorageError( | ||
| message: string, | ||
| error: unknown, | ||
| path: string, | ||
| ): StorageError { | ||
| return new StorageError( | ||
| message, | ||
| extractErrorCode(error), | ||
| path, | ||
| formatStorageErrorHint(error, path), | ||
| error instanceof Error ? error : undefined, | ||
| ); | ||
| } | ||
ndycode marked this conversation as resolved.
Show resolved
Hide resolved
ndycode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.