Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ jobs:

strategy:
matrix:
go-version: [1.12.x, 1.13.x, 1.20.x]
go-version: [1.20.x]
os: [ubuntu-latest, macos-latest, windows-latest]

env:
ENV: test

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v1
uses: actions/setup-go@v5
with:
go-version: ${{matrix.go-version}}

Expand Down
21 changes: 11 additions & 10 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
type ErrorCode string

const (
InternalError ErrorCode = "Internal Error"
NotFound ErrorCode = "Not Found"
InvalidArgument ErrorCode = "Invalid Argument"
Unauthenticated ErrorCode = "Unauthenticated"
PermissionDenied ErrorCode = "Permission Denied"
Unknown ErrorCode = "Unknown"
InternalError ErrorCode = "Internal Error"
NotFound ErrorCode = "Not Found"
InvalidArgument ErrorCode = "Invalid Argument"
Unauthenticated ErrorCode = "Unauthenticated"
PermissionDenied ErrorCode = "Permission Denied"
UnprocessableContent ErrorCode = "Unprocessable Content"
Unknown ErrorCode = "Unknown"
)

type customError struct {
Expand All @@ -30,7 +31,7 @@ func (code ErrorCode) New(msg string) error {
}

// Newf creates a new customError with formatted message
func (code ErrorCode) Newf(msg string, args ...interface{}) error {
func (code ErrorCode) Newf(msg string, args ...any) error {
return customError{code: code, originalError: fmt.Errorf(msg, args...)}
}

Expand All @@ -40,7 +41,7 @@ func (code ErrorCode) Wrap(err error, msg string) error {
}

// Wrapf creates a new wrapped error with formatted message
func (code ErrorCode) Wrapf(err error, msg string, args ...interface{}) error {
func (code ErrorCode) Wrapf(err error, msg string, args ...any) error {
return customError{code: code, originalError: errors.Wrapf(err, msg, args...)}
}

Expand All @@ -50,15 +51,15 @@ func New(msg string) error {
}

// Newf creates an InternalError error with formatted message
func Newf(msg string, args ...interface{}) error {
func Newf(msg string, args ...any) error {
return customError{
code: InternalError,
originalError: errors.New(fmt.Sprintf(msg, args...)),
}
}

// Wrapf an error with format string
func Wrapf(err error, msg string, args ...interface{}) error {
func Wrapf(err error, msg string, args ...any) error {
wrappedError := errors.Wrapf(err, msg, args...)

var customErr customError
Expand Down
10 changes: 10 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ var _ = Describe("Errors", func() {
Expect(fmt.Sprintf("%+v", errors.StackTrace(err))).To(ContainSubstring("/errors_test.go:"))
})

It("create an unprocessable content error", func() {
msg := "an error with a message"
err := errors.UnprocessableContent.New(msg)

Expect(errors.Code(err)).To(Equal(errors.UnprocessableContent))
Expect(err.Error()).To(Equal(msg))
Expect(errors.DisplayMessage(err)).To(Equal("Unprocessable Content"))
Expect(fmt.Sprintf("%+v", errors.StackTrace(err))).To(ContainSubstring("/errors_test.go:"))
})

It("creates an Unknown error", func() {
msg := "an error with a message"
err := errors.Unknown.New(msg)
Expand Down
4 changes: 1 addition & 3 deletions exports_113.go → exports.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build go1.13
// +build go1.13

package errors

import "errors"
Expand All @@ -9,4 +6,5 @@ var (
Is = errors.Is
As = errors.As
Unwrap = errors.Unwrap
Join = errors.Join
)
10 changes: 0 additions & 10 deletions exports_120.go

This file was deleted.

13 changes: 12 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
module github.com/neighborly/go-errors

go 1.13
go 1.20

require (
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.8.1
github.com/pkg/errors v0.9.1
)

require (
github.com/hpcloud/tail v1.0.0 // indirect
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd // indirect
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e // indirect
golang.org/x/text v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
)
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
Loading