doublestar.FilepathGlob() should return filepath.ErrBadPattern, not path.ErrBadPattern
sebastien-rosset opened this issue · comments
doublestar.FilepathGlob
should return filepath.ErrBadPattern
, not path.ErrBadPattern
. That's because doublestar.FilepathGlob
should be consistent with the filepath.Glob
behavior.
doublestar.Glob
correctly returns path.ErrBadPattern
for consistency with io/fs.Glob
.
That's super annoying that they aren't the same error. In the go code, io/fs specifically uses path.ErrBadPattern, why does filepath create a different error instance instead of just using path.ErrBadPattern, too? They even have the exact same error message! Ugh. /rant
In any event, I would argue that every function in doublestar should be using doublestar.ErrBadPattern because a library should be self-contained. It just so happens that this is equal to path.ErrBadPattern, but maybe in the future it won't be.
If doublestar.FilepathGlob()
does not return filepath.ErrBadPattern
, then it's not really a drop-in replacement as documented here: https://github.com/bmatcuk/doublestar/blob/master/utils.go#L68-L70. In that case I think we should clarify the return errors are not the same, so it's not possible to just replace one call by another. I.e. the caller needs to convert the error such that any existing logic continues to work.
I discovered there was a difference between filepath.ErrBadPattern
and path.ErrBadPattern
while trying to use doublestar.FilepathGlob()
here: https://github.com/get-woke/woke/pull/211/files#diff-ab967ab1a2f3a1b769106eeb7bfe892ef0e81d1d27811fa15be08e6749feee1fR184. If the error is not filepath.ErrBadPattern
, then replacing filepath.Glob
with doublestar.FilepathGlob()
is not a drop-in replacement. Not a big problem, but the returned error would have to be checked and converted to filepath.ErrBadPattern
.
I've added some documentation about ErrBadPattern