Giter Site home page Giter Site logo

vice's Introduction

vice

Standard bad behaviours for Go error values

GoDoc Alpha Quality Build Status GitHub tag BSD license codecov Go Report Card


Introduction

Introduction | Examples | Usage | Contributing

๐Ÿšง Disclaimer: vice is alpha quality software. The API may change without warning between revisions. ๐Ÿšง

vice provides bad behaviours for the new Go 2/1.13+ error values.

Examples

Introduction | Examples | Usage | Contributing

Create an error that implements NotFound() bool:

vice.New(vice.NotFound, "user not found")

Wrap an existing error, and add Timeout() bool:

vice.Wrap(err, vice.Timeout, "request timed out")

For complete examples and usage, see the GoDoc documentation.

Usage

Introduction | Examples | Usage | Contributing

vice defines common types of errors, as seen in existing packages, as expressed through methods on the errors of the form:

BehaviourName() bool // returns true

Errors of these types can be created and checked by vice. When used with Go 2 error value wrapping, intermediate code layers don't have to know about the behaviours or types of errors, and may add additional information, without altering how the error is handled in the topmost layer:

// Create an error when your database can't find a user record
err := vice.New(vice.NotFound, "user not found")

// many intermediate layers of code, passing the error on, and wrapping it
// ...

// In your central request handler middleware
if vice.Is(err, vice.NotFound) {
	// respond appropriately to the client
}

Building APIs on vice

vice/skip implements the vice API with an additional skip argument, allowing creation of APIs on top of vice that will not report themselves in error caller frames.

Contributing

Introduction | Examples | Usage | Contributing

I would love your help!

vice is still a work in progress. You can help by:

  • Opening a pull request to resolve an open issue.
  • Adding a feature or enhancement of your own! If it might be big, please open an issue first so we can discuss it.
  • Improving this README or adding other documentation to vice.
  • Letting me know if you're using vice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.