-
-
Notifications
You must be signed in to change notification settings - Fork 7
ref(fs): add safeReadFile helper for FIFO-safe config reads #819
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c47cb54
refactor(fs): add safeReadFile helper for FIFO-safe config reads
BYK cf4a776
fix(safe-read): test preReadCommonFiles directly + correct stale comment
BYK 6eed613
fix(sentryclirc): preserve narrow EPERM-etc. re-throw behavior
BYK 017a265
fix(sentryclirc): stat directly so EPERM/EIO/EISDIR surface properly
BYK 313ef62
chore(safe-read): drop unused re-exports
BYK 7c3a523
chore(sentryclirc): swap helper order so JSDoc is attached correctly
BYK 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
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,45 @@ | ||
| /** | ||
| * FIFO-safe file-read helper for user-controlled paths. | ||
| * | ||
| * Named pipes (FIFOs), commonly created by 1Password's `.env` symlink | ||
| * integration, cause `Bun.file(path).text()` to block indefinitely | ||
| * waiting for a writer. Any read of a path under the user's project | ||
| * tree or home directory needs a `stat`-based regular-file check | ||
| * first. | ||
| * | ||
| * Prefer this helper over calling `isRegularFile` + `Bun.file().text()` | ||
| * by hand: a single call, consistent error handling, no way to forget | ||
| * the guard. | ||
| */ | ||
|
|
||
| import { handleFileError, isRegularFile } from "./dsn/fs-utils.js"; | ||
|
|
||
| /** | ||
| * Read a file's text content, returning `null` when the path is: | ||
| * - missing / inaccessible (ENOENT / EACCES / EPERM / EISDIR / ENOTDIR) | ||
| * - not a regular file (FIFO, socket, device, symlink to any of these) | ||
| * - any other expected I/O-level failure routed through | ||
| * {@link handleFileError} | ||
| * | ||
| * Unexpected errors are captured to Sentry via `handleFileError` and | ||
| * also return `null`, so callers don't need their own try/catch. | ||
| * | ||
| * @param filePath - Absolute path to read. | ||
| * @param operation - Logical operation name, reported to Sentry when a | ||
| * stat or read fails unexpectedly. Keep it short and specific (e.g., | ||
| * `"sentryclirc.read"`, `"read-files.tool"`). | ||
| */ | ||
| export async function safeReadFile( | ||
| filePath: string, | ||
| operation: string | ||
| ): Promise<string | null> { | ||
| if (!(await isRegularFile(filePath, `${operation}.stat`))) { | ||
| return null; | ||
| } | ||
| try { | ||
| return await Bun.file(filePath).text(); | ||
| } catch (error) { | ||
| handleFileError(error, { operation, path: filePath }); | ||
| return null; | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.