Skip to content
Open
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
60 changes: 54 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
name: ci

permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
workflow_dispatch:
push:
branches:
- master
Comment on lines +11 to +12
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add main to the list, so that we can rename the default branch.

This commit could also be put before the go1.26 feature commit, making it part of the "baseline".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming branches does not seem compliant with maintenance mode.

pull_request:

jobs:
dummy:
runs-on: ubuntu-latest
build:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
goversion: ["1.20", "1.21", "1.22", "1.23", "1.24", "1.25", "1.26"]
steps:
- uses: docker/setup-buildx-action@v3
- uses: docker/bake-action@v7
with:
targets: build-all
env:
GO_VERSION: ${{ matrix.goversion }}
test:
runs-on: ubuntu-24.04
steps:
- uses: docker/setup-buildx-action@v3
- uses: docker/bake-action@v7
with:
targets: test
env:
COVER_FILENAME: "cover.out"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
disable_file_fixes: true
files: ./cover.out
token: ${{ secrets.CODECOV_TOKEN }}
test-os:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- run: go test -v ./...
lint:
runs-on: ubuntu-24.04
steps:
-
name: Checkout
uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v3
- uses: docker/bake-action@v7
with:
targets: lint-all
40 changes: 40 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: "2"

run:
timeout: 10m

formatters:
enable:
- gofmt
- goimports

linters:
default: standard
enable:
- bodyclose
- forbidigo
- gocritic
- gosec
- importas
- makezero
- misspell
- noctx
- nolintlint
- revive
- unconvert
- unparam
- whitespace
settings:
errcheck:
exclude-functions:
- io.WriteString
exclusions:
presets:
- std-error-handling
rules:
- linters:
- gosec
text: "G104"
- linters:
- staticcheck
text: "QF1008"
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#syntax=docker/dockerfile:1
#check=error=true

ARG GO_VERSION=1.26
ARG XX_VERSION=1.9.0

ARG COVER_FILENAME="cover.out"

FROM --platform=${BUILDPLATFORM} tonistiigi/xx:${XX_VERSION} AS xx

FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS golang
COPY --link --from=xx / /
WORKDIR /src
ARG TARGETPLATFORM

FROM golang AS build
RUN --mount=target=/root/.cache,type=cache \
--mount=type=bind xx-go build ./...

FROM golang AS runtest
ARG TESTFLAGS="-v"
ARG COVER_FILENAME
RUN --mount=target=/root/.cache,type=cache \
--mount=type=bind \
xx-go test -coverprofile=/tmp/${COVER_FILENAME} $TESTFLAGS ./...

FROM scratch AS test
ARG COVER_FILENAME
COPY --from=runtest /tmp/${COVER_FILENAME} /

FROM build
44 changes: 0 additions & 44 deletions Makefile

This file was deleted.

13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# errors [![Travis-CI](https://travis-ci.org/pkg/errors.svg)](https://travis-ci.org/pkg/errors) [![AppVeyor](https://ci.appveyor.com/api/projects/status/b98mptawhudj53ep/branch/master?svg=true)](https://ci.appveyor.com/project/davecheney/errors/branch/master) [![GoDoc](https://godoc.org/github.com/pkg/errors?status.svg)](http://godoc.org/github.com/pkg/errors) [![Report card](https://goreportcard.com/badge/github.com/pkg/errors)](https://goreportcard.com/report/github.com/pkg/errors) [![Sourcegraph](https://sourcegraph.com/github.com/pkg/errors/-/badge.svg)](https://sourcegraph.com/github.com/pkg/errors?badge)
# errors [![GoDoc](https://godoc.org/github.com/pkg/errors?status.svg)](https://pkg.go.dev/github.com/pkg/errors) [![Report card](https://goreportcard.com/badge/github.com/pkg/errors)](https://goreportcard.com/report/github.com/pkg/errors) [![Sourcegraph](https://sourcegraph.com/github.com/pkg/errors/-/badge.svg)](https://sourcegraph.com/github.com/pkg/errors?badge)

Package errors provides simple error handling primitives.

Expand Down Expand Up @@ -41,18 +41,13 @@ default:

[Read the package documentation for more information](https://godoc.org/github.com/pkg/errors).

## Roadmap
## Compared to the standard library's `errors` package

With the upcoming [Go2 error proposals](https://go.googlesource.com/proposal/+/master/design/go2draft.md) this package is moving into maintenance mode. The roadmap for a 1.0 release is as follows:

- 0.9. Remove pre Go 1.9 and Go 1.10 support, address outstanding pull requests (if possible)
- 1.0. Final release.
This package was initially built to manage chains of typed errors. Support for this was later added to the standard library's `errors` package via `Unwrap` methods. Unfortunately, the standard library's `errors` package does not support stack traces, so it cannot be used as a drop-in replacement for the features this package provides. This package will mostly work interoperably with the standard library's `errors` package; typed errors added in `pkg/errors` work fine in `errors.Is` and `errors.As`, and you can wrap them with other typed errors.

## Contributing

Because of the Go2 errors changes, this package is not accepting proposals for new functionality. With that said, we welcome pull requests, bug fixes and issue reports.

Before sending a PR, please discuss your change by raising an issue.
This package is in maintenance mode. New features that extend the scope of the package are not being accepted and should be implemented in other modules. Exceptions would be features that improve interoperability with the standard library's `errors` package when it receives new features, as `pkg/errors` should mostly be able to act as a drop-in replacement. Bug fixes and reports are welcome. CI will be maintained to make sure the package is tested against new versions of Go and Go linting tools.

## License

Expand Down
32 changes: 0 additions & 32 deletions appveyor.yml

This file was deleted.

10 changes: 10 additions & 0 deletions astype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !go1.26

package errors
Comment on lines +1 to +3
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit starts the work of picking up maintenance; I think it would make sense to move this (and forward) separate.

(Steps before this were just setting the baseline)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to last


// AsType finds the first error in err's chain that matches type E,
// and if so, returns that error value and true.
func AsType[E error](err error) (E, bool) {
var target E
return target, As(err, &target)
}
13 changes: 13 additions & 0 deletions astype_go126.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build go1.26

package errors

import (
stderrors "errors"
)

// AsType finds the first error in err's chain that matches type E,
// and if so, returns that error value and true.
func AsType[E error](err error) (E, bool) {
return stderrors.AsType[E](err)
}
6 changes: 2 additions & 4 deletions bench_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build go1.7

package errors

import (
Expand All @@ -25,7 +23,7 @@ func yesErrors(at, depth int) error {

// GlobalE is an exported global to store the result of benchmark results,
// preventing the compiler from optimising the benchmark functions away.
var GlobalE interface{}
var GlobalE any
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any was added in go1.18, and the module already had go1.20 as minimum; I think we can squash this one with the "fix linting" commit, or move it before the addition of the go1.26 features.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modernize is not same as lint. These changes make the code use the latest conventions but are not required for the code to work properly and lint pass in recent Go.


func BenchmarkErrors(b *testing.B) {
type run struct {
Expand Down Expand Up @@ -97,7 +95,7 @@ func BenchmarkStackFormatting(b *testing.B) {
name := fmt.Sprintf("%s-stacktrace-%d", r.format, r.stack)
b.Run(name, func(b *testing.B) {
err := yesErrors(0, r.stack)
st := err.(*fundamental).stack.StackTrace()
st := err.(*fundamental).StackTrace()
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down
57 changes: 57 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
variable "COVER_FILENAME" {
default = null
}

variable "GO_VERSION" {
default = null
}

target "default" {
targets = ["build"]
}

target "_all_platforms" {
platforms = [
"linux/amd64",
"linux/arm64",
"linux/arm/v7",
"linux/arm/v6",
"linux/386",
"linux/ppc64le",
"linux/s390x",
"linux/riscv64",
"darwin/amd64",
"darwin/arm64",
"windows/amd64",
"windows/arm64",
]
}

target "build" {
output = ["type=cacheonly"]
args = {
GO_VERSION = GO_VERSION
}
}

target "build-all" {
inherits = ["build", "_all_platforms"]
}

target "test" {
target = "test"
args = {
COVER_FILENAME = COVER_FILENAME
GO_VERSION = GO_VERSION
}
output = [COVER_FILENAME != null ? "." : "type=cacheonly"]
}

target "lint" {
dockerfile = "hack/dockerfiles/lint.Dockerfile"
output = ["type=cacheonly"]
}

target "lint-all" {
inherits = ["lint", "_all_platforms"]
}
Loading
Loading