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

Writes source at the end of the Display message #53

Closed
wants to merge 1 commit into from

Conversation

brooksprumo
Copy link
Contributor

Fixes #51

Comment on lines +71 to +82
OpenFile => write!(formatter, "failed to open file `{}`: {}", path, self.source),
CreateFile => write!(
formatter,
"failed to create file `{}`: {}",
path, self.source
),
CreateDir => write!(
formatter,
"failed to create directory `{}`: {}",
path, self.source
),
SyncFile => write!(formatter, "failed to sync file `{}`: {}", path, self.source),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that clippy fmt splits these into multiple lines. If instead we inline the variables into the format strings, the code can remain compact.

            // assume above there is a `let source = &self.source;`
            OpenFile => write!(formatter, "failed to open file `{path}`: {source}"),
            CreateFile => write!(formatter, "failed to create file `{path}`: {source}"),
            CreateDir => write!(formatter, "failed to create directory `{path}`: {source}"),
            SyncFile => write!(formatter, "failed to sync file `{path}`: {source}"),
            // etc

(Note, the code doesn't remain a single line for all the variants. Refer to this branch for the impl: https://github.com/brooksprumo/fs-err/blob/source-inline/src/errors.rs)

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.

Display does not include source
2 participants