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

Top 6.3% on proxy.golang.org
Top 5.8% dependent packages on proxy.golang.org
Top 4.7% dependent repos on proxy.golang.org
Top 9.8% forks on proxy.golang.org

proxy.golang.org : github.com/mpvl/errc

Package errc simplifies error and defer handling. Package errc is a burner package: a proof-of-concept to explore better semantics for error and defer handling. Error handling and deferring using this package looks like: Checking for a nil error is replaced by a call to Must on an error catcher. A defer statement is similarly replaced by a call to Defer. Error handling in Go can also be tricky to get right. For instance, how to use defer may depend on the situation. For a Close method that frees up resources a simple use of defer suffices. For a CloseWithError method where a nil error indicates the successful completion of a transaction, however, it should be ensured that a nil error is not passed inadvertently, for instance when there is a panic if a server runs out of memory and is killed by a cluster manager. For instance, a correct way to commit a file to Google Cloud Storage is: The err variable is initialized to errPanicking to ensure a non-nil err is passed to CloseWithError when a panic occurs. This ensures that a panic will not cause a corrupted file. If all went well, a separate path used to collect the error returned by Close. Returning the error from Close is important to signal retry logic the file was not successfully written. Once the Close of w is successful all further errors are irrelevant. The error of the first Close is therefor willfully ignored. These are a lot of subtleties to get the error handling working properly! The same can be achieved using errc as follows: Observe how a straightforward application of idiomatic check-and-defer pattern leads to the correct results. The error of the first Close is now ignored explicitly using the Discard error handler, making it clear that this is what the programmer intended. Error handlers can be used to decorate errors, log them, or do anything else you usually do with errors. Suppose we want to use github.com/pkg/errors to decorate errors. A simple handler can be defined as: This handler can then be used as follows:

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/mpvl/errc
License: BSD-3-Clause
Latest release: over 7 years ago
First release: over 7 years ago
Namespace: github.com/mpvl
Dependent packages: 1
Dependent repositories: 1
Stars: 74 on GitHub
Forks: 3 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: about 2 months ago

    Loading...
    Readme
    Loading...