Skip to content

os: document behavior of IsNotExist, IsExist, etc. for nil errors #31065

Closed
@dpinela

Description

@dpinela

The IsNotExist, IsExist, IsPermission and IsTimeout functions in package os all return false when passed a nil error, but the documentation isn't too clear about that. I presume the behavior is intentional, since there are tests for it (except for IsTimeout?). Being able to rely on this property would be nice, as it allows one to write code like the following, to treat such errors specially:

if os.IsNotExist(err) {
   // ...
} else if err != nil {
  // ...
}

I think the root of the issue is that the term "the error" in these functions' docs is ambiguous - it could mean an error value (which can be nil) or an error condition (which is represented by a non-nil error value).

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsFixThe path to resolution is known, but the work has not been done.SuggestedIssues that may be good for new contributors looking for work to do.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions