net/http: toHTTPError() should use errors.Is() function #44923
Labels
FrozenDueToAge
help wanted
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am using
http.FileSystem
with some code that wraps errors with a stack trace:When a file does not exists, the wrapped
os.ErrNotExist
is not detected by the net/httptoHTTPError()
function, because it is still usingos.IsNotExists(err)
and therefore the function returnsStatusInternalServerError
instead ofStatusNotFound
. See:go/src/net/http/fs.go
Lines 673 to 675 in 1811aea
By replacing
os.IsNotExists(err)
witherrors.Is(err, os.ErrNotExist)
theos.ErrNotExists
condition is dectected correctly:What did you expect to see?
toHTTPError()
returningStatusNotFound
What did you see instead?
toHTTPError()
returningStatusInternalServerError
The text was updated successfully, but these errors were encountered: