Coder Social home page Coder Social logo

errata's Introduction

errata

errata is a general purpose, language-agnostic toolkit for error code enumeration (ECE).

ECE is the process of defining all the ways in which your software can fail. Think of it as negative documentation (describing how your system fails as opposed to how it works).

Consider a web application. Aren't HTTP status codes enough? No. They are sometimes useful (404 Not Found is fairly clear), but others are so vague as to be pretty meaningless (500 Internal Server Error). Often an additional semantic layer is required to communicate what exactly went wrong, and what the caller (be they a human, an API client, etc) can do in response. HTTP status codes are perfect for describing the category of problem (4xx client error, 5xx server error), but insufficient for the complex software of today.

Major API vendors such as Twilio, Instagram, and Google Cloud recognise this and use ECE in some form. errata aims to provide a mechanism for any software to deliver world-class error handling.

Basic Concepts

errata's philosophy is that errors should have at least a static error code and a human-readable message.

  • the code is searchable, and because it's static it becomes more easily searchable
  • the message is displayed to the user alongside the code, to provide immediate context, and ideally to give an insight into what went wrong

Besides the basic code and message, including other valuable metadata like a unique reference (particularly useful in SaaS applications), labels, user guides, etc can be included.

Definitions

errata uses the HCL structured configuration language, used primarily by Terraform. It's extensible, simple to read and write, and frankly - fuck YAML.

version = "0.1"

error "file-not-found" {
  message    = "File path is incorrect or inaccessible"
  categories = ["file"]
  guide      = "Ensure the given file exists and can be accessed"
  args       = [
    arg("path", "string")
  ]
  labels     = {
    severity = "warn"
  }
}

...

The above example defines the code (file-not-found) and the message, along with some other useful metadata (more on this below).

So, what can this definitions file be used for?

Code Generation

errata provides a language-agnostic mechanism for generating code based on these definitions using the Pongo2 templating engine.

errata comes with a CLI tool called eish (errata interactive shell, pronounced "eɪʃ") which generates code based on given errata definitions.

$ eish generate --source=errata.hcl --template=golang --package=errors

This will generate a single file with all error definitions. See the sample application which uses errata definitions (and rather recursively, the errata library also uses errata definitions).

Web UI

eish also provides a simple web UI, allowing your errata definitions to be viewed and searched.

$ eish serve --source=errata.hcl

The web UI by default runs on port 37707.

Web UI

Supported Languages

If your language of choice is not yet available, consider contributing a template!

errata uses the Pongo2 templating engine

  • Golang (reference implementation)

The code produced by errata aims to be:

  • idiomatic
  • easy to use
  • using native error/exception types as much as possible

errata's People

Contributors

dannykopping avatar jdbaldry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

sasswart jdbaldry

errata's Issues

Format strings are not substituted in error message

I expected that usage of %q or other format strings would result in the error message substituting those for the arguments defined in args.

Concrete example using eish serve, built at the latest release, on a .go file to trigger an error with format strings.
Errata source at 39fda0b:

$ eish serve --source ~/ext/dannykopping/errata/errata.go

Returns:

eish encountered an error: [errata-serve-web-ui] <[email protected]/command.go:163> Cannot serve web UI for datasource %q (path="/home/jdb/ext/dannykopping/errata/errata.go"). For more details, see https://dannykopping.github.io/errata/errata/errata-serve-web-ui
...

I expected something like:

eish encountered an error: [errata-serve-web-ui] <[email protected]/command.go:163> Cannot serve web UI for datasource "/home/jdb/ext/dannykopping/errata/errata.go". For more details, see https://dannykopping.github.io/errata/errata/errata-serve-web-ui
...

Macro `quote_map` keys are not sorted correctly

This is used in labels fields, and even though the keyword sorted is passed as per pongo2 documentation, it doesn't sort correctly.

There's some really nasty reflection going on in github.com/flosch/pongo2/v5/value.go:IterateOrder

If these fields are not sorted correctly, it will lead to non-idempotent regeneration of the error code.

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.