Skip to content

Commit

Permalink
Add github actions workflows, update readme, add license
Browse files Browse the repository at this point in the history
  • Loading branch information
Rheisen committed Mar 15, 2024
1 parent 78f9a3a commit b3c089b
Show file tree
Hide file tree
Showing 9 changed files with 902 additions and 81 deletions.
3 changes: 3 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage:
status:
patch: off
26 changes: 26 additions & 0 deletions .github/workflows/golang-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: go tests

on: [push, pull_request]

jobs:
gotest:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
go: [1.19]
steps:
- name: checkout
uses: actions/checkout@v3
- name: go setup
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: build
run: go build -v ./...
- name: test
run: go test -race -coverprofile coverage.txt -covermode atomic
- name: upload coverage
uses: codecov/codecov-action@v3
with:
files: coverage.txt
45 changes: 45 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.50.1

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
15 changes: 15 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ linters-settings:
nolintlint:
require-explanation: true
require-specific: true
depguard:
rules:
main:
files:
- $all
- "!$test"
allow:
- $gostd
- github.com/rheisen/berr
test:
files:
- $test
allow:
- $gostd
- github.com/rheisen/berr

linters:
disable-all: true
Expand Down
606 changes: 606 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# `berr`: better errors for go

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![GoDoc](https://godoc.org/github.com/rheisen/berr?status.svg)](https://pkg.go.dev/github.com/rheisen/berr)
[![Go Report Card](https://goreportcard.com/badge/github.com/rheisen/berr)](https://goreportcard.com/report/github.com/rheisen/berr)
[![Build Status](https://github.com/rheisen/berr/actions/workflows/golang-test.yml/badge.svg?branch=main)](https://github.com/rheisen/berr/actions/workflows/golang-test.yml)
[![codecov.io](https://codecov.io/github/rheisen/berr/coverage.svg?branch=main)](https://codecov.io/github/rheisen/berr?branch=main)


`berr` is an errors package that provides simple functions for creating more descriptive errors.

```
Expand All @@ -18,10 +25,11 @@ for creating really powerful errors.
1. Errors need to serve the needs of different audiences, audiences with often conflicting interests (E.g. developers
vs. end-users of APIs and Applications). When creating a `berr.Error`, provide a message that is safe and valuable to
end-users, and add `berr.Attachment` structures to provide additional context relevant for those different audiences.
By default, berr provides `detail`, `metadata`, and `error` attachments. The `detail` attachment is not sensitive, and
intended for end-users, while `metadata` and `error` attachments are sensitive (intended for developers).
Berr provides `detail`, `metadata`, and `error` attachments. The `detail` attachment is not sensitive, and intended for
providing additional context to end-users, while `metadata` and `error` attachments are sensitive (e.g. intended for
developers / debugging).

2. Errors should be sensitive by default, and not reveal or leak sensitive information / sensitive attachments without
2. Errors should be sensitive by default, and not reveal or leak sensitive information (sensitive attachments) without
an explicit call to do so. `berr.Error.String()` will output the error type and the message it was initially suplied
with, while `berr.Error.Error()` will output the `berr.Error.String()` in addition to the output of `.Error()` on the
next error (if one exists). A JSON rendering of a `berr.Error` model will only expose the message, error type, and
Expand Down Expand Up @@ -63,8 +71,3 @@ the `berr.Error` interface with the `.Metadata()` method, and will also be outpu
* `Error.Map() map[string]any`
* `Error.FullMap() map[string]any`
* `Error.Unwrap()`

### Examples

```go
```
2 changes: 1 addition & 1 deletion error_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type berr struct {
}

func (e *berr) String() string {
return fmt.Sprintf("[%s error] %s", e.ErrTypeString, e.ErrMessage)
return fmt.Sprintf("[%s_error] %s", e.ErrTypeString, e.ErrMessage)
}

func (e *berr) Error() string {
Expand Down
Loading

0 comments on commit b3c089b

Please sign in to comment.