Skip to content
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

Consider using fs-err to improve I/O error messages #270

Open
edmorley opened this issue Sep 9, 2024 · 1 comment
Open

Consider using fs-err to improve I/O error messages #270

edmorley opened this issue Sep 9, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@edmorley
Copy link
Member

edmorley commented Sep 9, 2024

The fs-err crate aims to improve error messages for I/O errors by eg including the paths of the file/... that triggered the error:
https://crates.io/crates/fs-err

It's supposed to be a drop-in replacement, however, testing locally I found that it made the error message worse in some cases.

For example, before switching to fs-err, the output from the runtime_txt_io_error integration test (whose fixture intentionally has runtime.txt that contains invalid unicode) was:

[Error: Unable to read runtime.txt]
An unexpected error occurred whilst reading the (optional) runtime.txt file.

Details: I/O Error: stream did not contain valid UTF-8

And after:

[Error: Unable to read runtime.txt]
An unexpected error occurred whilst reading the (optional) runtime.txt file.

Details: I/O Error: failed to read from file `/workspace/runtime.txt`

With the error message temporarily changed to print the debug output, we can more clearly see the issue:

[Error: Unable to read runtime.txt]
An unexpected error occurred whilst reading the (optional) runtime.txt file.

Details: I/O Error: Custom { kind: InvalidData, error: Error { kind: Read, source: Error { kind: InvalidData, message: "stream did not contain valid UTF-8" }, path: "/workspace/runtime.txt" } }

ie: fs-err wraps the underlying cause of the io::Error, and that cause is not included in the display representation of the top level error. Instead, one has to manually check for and print error.source(). This is apparently by design (which I get, but it still means more work to use fs-err, and it not quite being the drop-in replacement it promises):
andrewhickman/fs-err#51

It may still be worth using fs-err - however, if we adopt it then further buildpack changes will be required to maintain all error message content (such as having the log_io_error function print a "caused by" line iff error.sources() is Some).

@edmorley
Copy link
Member Author

edmorley commented Sep 9, 2024

Filed andrewhickman/fs-err#59.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant