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
24 changes: 13 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,35 @@ on:
- release-*
env:
PRE_RELEASE: ${{ github.ref == 'refs/heads/main' && 'development' || '' }}
GO_VERSION: "1.23"
GO_LANGCI_LINT_VERSION: v2.0.2
GO_TESTSUM_VERSION: "1.11.0"
GO_VER: "1.26"
GO_LANGCI_LINT_VER: v2.11.4
GO_TESTSUM_VER: "1.13.0"

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
-
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
-
name: Setup Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
go-version-file: 'go.mod'
-
name: Lint
uses: golangci/golangci-lint-action@v7
uses: golangci/golangci-lint-action@v9
with:
version: ${{ env.GO_LANGCI_LINT_VERSION }}
version: ${{ env.GO_LANGCI_LINT_VER }}
verify: false # `golangci-lint config verify` checks against the latest schema instead of its own version.
args: --timeout=30m
-
name: Test Setup
uses: autero1/action-gotestsum@v2.0.0
uses: gertd/action-gotestsum@v3.0.0
with:
gotestsum_version: ${{ env.GO_TESTSUM_VERSION }}
gotestsum_version: ${{ env.GO_TESTSUM_VER }}
-
name: Test
run: |
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/gitleaks-check.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/gitleaks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: gitleaks
on:
pull_request:
push:
workflow_dispatch:
schedule:
- cron: "0 4 * * *" # run once a day at 4 AM
jobs:
scan:
name: gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
60 changes: 55 additions & 5 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,91 @@ linters:
disable:
- depguard
- exhaustruct
- gochecknoglobals # no configuration options
- nlreturn # redundant with wsl
- gochecknoglobals # no configuration options
- nlreturn # redundant with wsl
- noinlineerr
- paralleltest
- revive
- thelper
- varnamelen
- wrapcheck
- wsl

settings:
cyclop:
max-complexity: 12

errcheck:
exclude-functions:
- fmt.Fprint
- fmt.Fprintf
- fmt.Fprintln
- os.Close

funlen:
lines: 80
statements: 60
ignore-comments: true

gocritic:
enable-all: false
disable-all: true
enabled-checks:
- commentedOutCode

gomoddirectives:
replace-allow-list:
- github.com/slok/go-http-metrics

gosec:
excludes:
- G104 # Errors unhandled
- G304 # Potential file inclusion via variable (see https://github.com/golang/go/issues/67002)

ireturn:
allow:
- error
- empty
- stdlib
- generic
- proto.Message
# - plugins.Plugin
# - decisionlog.DecisionLogger
# - resolvers.DirectoryResolver
# - resolvers.RuntimeResolver
# - v3.ReaderClient
# - v1.AccessClient
# - v1.AccessServer
# - v3.ModelServer
# - v3.ReaderServer
# - v3.WriterServer
# - v3.ExporterServer
# - v3.ImporterServer
# - datasync.SyncClient
# - grpc.ServerOption

lll:
line-length: 150

recvcheck:
exclusions:
- "*.Map"

tagliatelle:
case:
rules:
json: snake
yaml: snake

wsl_v5:
allow-first-in-block: true
allow-whole-block: false
branch-max-lines: 2

exclusions:
generated: lax

formatters:
enable:
- gofmt
- gofumpt
- goimports
disable:
- gci # use gofumpt
1 change: 1 addition & 0 deletions custom_error_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func CustomErrorHandler(
logger.Error().Err(conversionErr).Msg("Failed to detect http status code associated with this AsertoError")
} else {
var httpStatusError runtime.HTTPStatusError

httpStatusError.Err = err
httpStatusError.HTTPStatus = code
runtime.DefaultHTTPErrorHandler(ctx, gtw, runtimeMarshaler, httpResponseWriter, httpRequest, &httpStatusError)
Expand Down
28 changes: 12 additions & 16 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ var (
asertoErrors = make(map[string]*AsertoError) //nolint:gochecknoglobals
)

func NewAsertoError(code string, statusCode codes.Code, httpCode int, msg string) *AsertoError {
asertoError := &AsertoError{code, statusCode, msg, httpCode, map[string]string{}, nil}
asertoErrors[code] = asertoError

return asertoError
}

// AsertoError represents a well known error
// coming from an Aserto service.
type AsertoError struct {
Expand All @@ -46,6 +39,13 @@ type AsertoError struct {
errs []error
}

func NewAsertoError(code string, statusCode codes.Code, httpCode int, msg string) *AsertoError {
asertoError := &AsertoError{code, statusCode, msg, httpCode, map[string]string{}, nil}
asertoErrors[code] = asertoError

return asertoError
}

func (e *AsertoError) Data() map[string]string {
return e.Copy().data
}
Expand All @@ -64,9 +64,7 @@ func (e *AsertoError) SameAs(err error) bool {
func (e *AsertoError) Copy() *AsertoError {
dataCopy := make(map[string]string, len(e.data))

for k, v := range e.data {
dataCopy[k] = v
}
maps.Copy(dataCopy, e.data)

return &AsertoError{
Code: e.Code,
Expand Down Expand Up @@ -127,7 +125,7 @@ func (e *AsertoError) Fields() map[string]any {
return result
}

// Associates err with the AsertoError.
// Err associates err with the AsertoError.
func (e *AsertoError) Err(err error) *AsertoError {
if err == nil {
return e
Expand Down Expand Up @@ -293,7 +291,7 @@ func (e *AsertoError) Ctx(ctx context.Context) error {
return WithContext(e, ctx)
}

// Returns an Aserto error based on a given grpcStatus. The details that are not of type errdetails.ErrorInfo are dropped.
// FromGRPCStatus returns an Aserto error based on a given grpcStatus. The details that are not of type errdetails.ErrorInfo are dropped.
// and if there are details from multiple errors, the aserto error will be constructed based on the first one.
func FromGRPCStatus(grpcStatus status.Status) *AsertoError {
var result *AsertoError
Expand All @@ -320,9 +318,7 @@ func FromGRPCStatus(grpcStatus status.Status) *AsertoError {
return result
}

/**
* Retrieves the most inner logger associated with an error.
*/
// Logger retrieves the most inner logger associated with an error.
func Logger(err error) *zerolog.Logger {
var (
logger *zerolog.Logger
Expand Down Expand Up @@ -384,7 +380,7 @@ func UnwrapAsertoError(err error) *AsertoError {
return nil
}

// Returns true if the given errors are Aserto errors with the same code or both of them are nil.
// Equals returns true if the given errors are Aserto errors with the same code or both of them are nil.
func Equals(err1, err2 error) bool {
asertoErr1 := UnwrapAsertoError(err1)
asertoErr2 := UnwrapAsertoError(err2)
Expand Down
1 change: 1 addition & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func TestLoggerWithNilError(t *testing.T) {
assert := require.New(t)

var err error

logger := cerr.Logger(err)
assert.Nil(logger)
}
Expand Down
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module github.com/aserto-dev/errors

go 1.23.0
go 1.25.0

toolchain go1.24.1
toolchain go1.26.2

require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.34.0
github.com/stretchr/testify v1.10.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb
google.golang.org/grpc v1.70.0
github.com/rs/zerolog v1.35.0
github.com/stretchr/testify v1.11.1
google.golang.org/genproto/googleapis/rpc v0.0.0-20260406210006-6f92a3bedf2d
google.golang.org/grpc v1.80.0
)

require (
Expand All @@ -20,10 +20,10 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
golang.org/x/net v0.36.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb // indirect
google.golang.org/protobuf v1.36.5 // indirect
golang.org/x/net v0.52.0 // indirect
golang.org/x/sys v0.43.0 // indirect
golang.org/x/text v0.35.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260406210006-6f92a3bedf2d // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading