Skip to content

.IsError(...) predicate could be more flexible #21

@maargenton

Description

@maargenton

Currently, .IsError(...) only accepts either nil to check there is no error, or another error that must match directly or indirectly through error wrapping.

Suggested extended behavior:

.IsError(nil)       // no error -- currently supported
.IsError()          // any error
.IsError(sentinel)  // match specific error -- currently supported
.IsError(str)       // error message contains string
.IsError(regex)     // error message matches regexp

Redefining it a IsError(match ...any) preserves backward compatibility (currently accepting 1 error argument), supports the new 0 argument case, and supports non-error expectations. Specifying more than 1 argument or unsupported argument types can be handled as an error. Similar pattern is used in other frameworks (e.g. fiber) to simulate optional argument.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions