Skip to content

Commit 2cde550

Browse files
authored
Merge pull request #50 from LandonTClipp/relative_to
Wrap sentinel error in RelativeTo
2 parents afb65cb + d1f091c commit 2cde550

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var (
1212
ErrInvalidAlgorithm = fmt.Errorf("invalid algorithm specified")
1313
// ErrLstatNotPossible specifies that the filesystem does not support lstat-ing
1414
ErrLstatNotPossible = fmt.Errorf("lstat is not possible")
15+
// ErrRelativeTo indicates that we could not make one path relative to another
16+
ErrRelativeTo = fmt.Errorf("failed to make path relative to other")
1517
// ErrStopWalk indicates to the Walk function that the walk should be aborted
1618
ErrStopWalk = fmt.Errorf("stop filesystem walk")
1719
)

path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func (p *Path) RelativeTo(other *Path) (*Path, error) {
433433
var relativeBase int
434434
for idx, part := range otherParts {
435435
if idx >= len(thisParts) || thisParts[idx] != part {
436-
return p, fmt.Errorf("%s does not start with %s", thisPathNormalized, otherPathNormalized)
436+
return p, fmt.Errorf("%s does not start with %s: %w", thisPathNormalized, otherPathNormalized, ErrRelativeTo)
437437
}
438438
relativeBase = idx
439439
}

0 commit comments

Comments
 (0)