github.com/alphazero/goerror
package goerror provides for creation of semantic error types. Using the stdlib error package, when trying to discern the error type returned by a function, we can either (a) compare to a well-known error reference (for example, io.EOF), or (b) we have to parse the actual error message. The former, e.g. io.EOF, is fine for basic cases, but obviously won't allow for call-site specific information in the error. For example, let's say we create an error for asserting input arg correctness, something like an AsssertError, or IllegalArgumentError. We can try pattern (a) per io.EOF, in which case we can certainly return that error, but can't provide additional info such as which precise arg caused the error. Or we can return a plain jane error with a formatted message, in which case we can't immediately tell what 'kind' of error was returned. This package addresses this concern by providing error 'types' that can be generically defined at (some) package level and then used with explicit additional details. Errors are created using 'Define'. (Note, not 'New', since this merely defines an error type). Such error types can then be 'instantiated' using the defintion, wherever one would normally create and/or return a generic error. And in the functional callsite, we can specifically check to see what type of error we got.
proxy.golang.org
v0.0.0-20160410032305-8e7a8d87517b
almost 10 years ago
1
Links
| Registry | proxy.golang.org |
| Source | Repository |
| Docs | Documentation |
| JSON API | View JSON |
| CodeMeta | codemeta.json |
Package Details
| PURL |
pkg:golang/github.com/alphazero/goerror
spec |
| License | BSD-2-Clause |
| Namespace | github.com/alphazero |
| First Release | almost 10 years ago |
| Last Synced | 27 days ago |
Repository
| Stars | 0 on GitHub |
| Forks | 0 on GitHub |