libutil: Make MemorySourceAccessor throw more precise errors#14862
libutil: Make MemorySourceAccessor throw more precise errors#14862
Conversation
Makes the error messages render paths correctly, also introduces a new hierarchy of error classes for SourceAccessor related errors that we might want to handle differently (e.g. like when doing a readFile on a directory and such). This should make it easier to implement better UnionSourceAccessor and AllowListSourceAccessor by catching these errors consistently.
Radvendii
left a comment
There was a problem hiding this comment.
This seems like an improvement to me, amd I don't see any problems. Approved.
A couple of tests fail locally, but they also fail on master, and they don't fail in CI, so I think that's an unrelated issue.
My comments are additional improvements that looking at this PR made me think of. We could roll them into this PR or tackle them separately or not at all.
Additional behaviours we might want to add tests for:
readDirectory(CanonPath("/"))with an empty source accessorreadFile()/readDirectory()called on a symlinkcreateRegularFile()/createDirectory()when the file already exists and is a symlinkcreate*()when a parent directory is a symlink (either to a directory (valid) or to a regular file (invalid))createFile()on something that's already a filecreateDirectory()on something that's already a directory
| r->contents = std::move(contents); | ||
| else | ||
| throw Error("file '%s' is not a regular file", path); | ||
| throw NotARegularFile("file '%s' is not a regular file", showPath(path)); |
There was a problem hiding this comment.
should this be "cannot be created because it already exists and is not a regular file" or something like that?
There was a problem hiding this comment.
Yeah, ideally. I didn't want to make the scope too large for now, since MemorySourceAccessor isn't very user-facing.
| throw Error("directory '%s' cannot be created because some parent file is not a directory", dst.showPath(path)); | ||
|
|
||
| if (!std::holds_alternative<File::Directory>(f->raw)) | ||
| throw Error("file '%s' is not a directory", path); |
There was a problem hiding this comment.
similar transformation here "cannot be created because it already exists and is not a directory"
Motivation
Makes the error messages render paths correctly, also introduces a new hierarchy of error classes for SourceAccessor related errors that we might want to handle differently (e.g. like when doing a readFile on a directory and such). This should make it easier to implement better UnionSourceAccessor and AllowListSourceAccessor by catching these errors consistently.
Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.