Include the failing path in Path errors - #468
Open
dmisiuk wants to merge 1 commit into
Open
Conversation
dmisiuk
force-pushed
the
issue-399-path-error-context
branch
from
August 2, 2026 17:49
46d9b26 to
18c8d0d
Compare
dmisiuk
marked this pull request as ready for review
August 2, 2026 18:03
dmisiuk
force-pushed
the
issue-399-path-error-context
branch
from
August 3, 2026 17:22
18c8d0d to
3779aea
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Draft for #399 —
Patherrors now carry the path that failed.Shape agreed with @Anton-4 on Zulip: positional payload, no
operationfield for now, andFile.open_reader!enriched in this PR too.The change
Today every
Patheffect returnsPathErr(IOErr), so a failure gives no clue which path — or which of several calls — failed:The path is already in hand at the failure point, so this is pure Roc in
Path.roc— no host or glue changes. The two converters take the path and put it in the error:That rendering is free —
main_for_host!prints viaStr.inspectandPathalready hasto_inspect.Why positional rather than a record
Sqlite.rocalready uses a positional payload for exactly this shape (SqliteErr(ErrCode, Str)), and it keeps the common match a one-liner:The platform's own
is_file!/is_dir!/is_sym_link!/exists!are written that way, and they stay one-liners here. With a record payload they would each become a full destructure — there are no partial record patterns anywhere in the repo. The record form (likeCmd.FailedToGetExitCode({ command, err })) is the alternative under discussion.Breaking change — narrow
?,? |err| …,??andErr(_)all keep working, since the error type is open and inferred. Only an explicit destructure of the inner tag breaks:Path.rocitself (is_file!and friends), nowErr(PathErr(NotFound, _))examples/error-handling.rocandexamples/file-accessed-modified-created-time.rocscripts/test_spec.jsonthat matched the rendered error textThat last one is a category I'd missed until the suite caught it — worth noting for whoever reviews the blast radius.
Notes for review
examples/error-handling.rocnow demonstrates both styles: naming the path in the message, and_when it adds nothing.file-size.rocassertion asserts thePathErr(NotFound, Path.prefix rather than the whole value: that case also runs on Windows, where the path renders asPath.windows(...)instead ofPath.unix(...). This matches how other inspect-rendered errors are asserted (VarNotFound(OsStr.,Debug: Path.).hard_link!andrename!both attribute the error to their source operand (original/from), which is what a missing-file failure refers to; some failures concern the destination instead (AlreadyExists), so both carry a doc note. I hadhard_link!on the destination at first, which madehard_link!("missing.txt", "new")reportNotFoundagainst the file being created — actively misleading, so it's fixed here.operationis deliberately not included, per the thread — easy to add later if it turns out to be wanted.Three
expectblocks cover the converters: the path survives into the error (including raw non-UTF-8 bytes), andOkpasses through. Each was verified to fail when its expected value is altered. Note these have to be match-based rather than==, sinceIOErrdoesn't support equality — that's pre-existing, not introduced here.Full
./scripts/test.pypasses — host build plus every example.File.open_reader!It takes a
Pathand used to return a bareFileErr(err), so whether an open failure named the path depended on which module you called. It now reportsPathErr(err, path)— the same tag as the whole-file operations rather than a second one, because the two shapes have to unify:File.Reader.read_line!keeps returningFileErr(IOErr)(aReadercarries no path), and the compiler rejects one tag name used at two arities, so chaining an open with a read would not type-check otherwise. UsingPathErralso means an open and aPathoperation collapse into a single error type in one?chain.