Ecosyste.ms: Packages

An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 4.1% on proxy.golang.org
Top 0.9% dependent packages on proxy.golang.org
Top 1.3% dependent repos on proxy.golang.org
Top 10.0% forks on proxy.golang.org
Top 1.3% docker downloads on proxy.golang.org

proxy.golang.org : github.com/lainio/err2

Package err2 provides three main functionality: The err2 package drives programmers to focus on error handling rather than checking errors. We think that checks should be so easy that we never forget them. The CopyFile example shows how it works: The github.com/lainio/err2/try package provides convenient helpers to check the errors. For example, instead of we can write Note that try.To functions are as fast as if err != nil statements. Please see the github.com/lainio/err2/try package documentation for more information about the error checks. err2 offers optional stack tracing. And yes, it's fully automatic. Just call at the beginning your app, e.g. main function, or set the tracers programmatically (before flag.Parse if you are using that): Note. Since Catch's default mode is to recover from panics, it's a good practice still print their stack trace. The panic tracer's default values is os.Stderr. The default error tracer is nil. Note that both panic and error traces are optimized by err2 package. That means that the head of the stack trace isn't the panic function, but an actual line that caused it. It works for all three categories: The last two types are handled as panics in the error handling functions given to Handle and Catch. Same err2 capablities support automatic logging like the Catch and [try.Result.Logf] functions. To be able to tune up how logging behaves we offer a tracer API: The err2 package supports Go's flags. All you need to do is to call flag.Parse. And the following flags are supported (="default-value"): Note that you have called SetErrorTracer and others, before you call flag.Parse. This allows you set the defaults according your app's need and allow end-user change them during the runtime. Package err2 relies on declarative control structures to achieve error and panic safety. In every function which uses err2 or try package for error-checking has to have at least one declarative error handler if it returns error value. If there are no error handlers and error occurs it panics. We think that panicking for the errors is much better than not checking errors at all. Nevertheless, if the call stack includes any err2 error handlers like Handle the error is handled where the handler is saved to defer-stack. (defer is not lexically scoped) err2 includes many examples to play with like previous CopyFile. Please see them for more information.

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/lainio/err2
Keywords: assertion-library, error, error-handling, errors, go, golang, stacktrace, try-catch, unit-testing
License: MIT
Latest release: 5 months ago
First release: over 3 years ago
Namespace: github.com/lainio
Dependent packages: 27
Dependent repositories: 21
Stars: 48 on GitHub
Forks: 6 on GitHub
Docker dependents: 6
Docker downloads: 1,097
See more repository details: repos.ecosyste.ms
Last synced: 11 days ago

    Loading...
    Readme
    Loading...