Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/golang.org/x/term-0.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
decentralgabe authored Apr 16, 2024
2 parents d1ab966 + dcd73d6 commit b1b9218
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.22.1
go-version: 1.22.2

- name: Install Mage
run: go install github.com/magefile/mage
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.22.1
go-version: 1.22.2

- name: Install Mage
run: go install github.com/magefile/mage
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.22.1
go-version: 1.22.2
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ When you're ready you may:

| Requirement | Tested Version | Installation Instructions |
|-------------|----------------|--------------------------------------------------------|
| Go | 1.22.1 | [go.dev](https://go.dev/doc/tutorial/compile-install) |
| Go | 1.22.2 | [go.dev](https://go.dev/doc/tutorial/compile-install) |
| Mage | 1.13.0-6 | [magefile.org](https://magefile.org/) |

### Go
Expand All @@ -23,7 +23,7 @@ You may verify your `go` installation via the terminal:

```
$> go version
go version go1.22.1 darwin/amd64
go version go1.22.2 darwin/amd64
```

If you do not have go, we recommend installing it by:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
⚠️ This repository is not actively being maintained. For a go SDK please look at [web5-go](https://github.com/TBD54566975/web5-go/). ⚠️

[![godoc ssi-sdk](https://img.shields.io/badge/godoc-ssi--sdk-blue)](https://pkg.go.dev/github.com/TBD54566975/ssi-sdk)
[![go version 1.22.1](https://img.shields.io/badge/go_version-1.22.1-brightgreen)](https://golang.org/)
[![go version 1.22.2](https://img.shields.io/badge/go_version-1.22.2-brightgreen)](https://golang.org/)
[![Go Report Card A+](https://goreportcard.com/badge/github.com/TBD54566975/ssi-sdk)](https://goreportcard.com/report/github.com/TBD54566975/ssi-sdk)
[![license Apache 2](https://img.shields.io/badge/license-Apache%202-black)](https://github.com/TBD54566975/ssi-sdk/blob/main/LICENSE)
[![issues](https://img.shields.io/github/issues/TBD54566975/ssi-sdk)](https://github.com/TBD54566975/ssi-sdk/issues)
Expand Down
2 changes: 1 addition & 1 deletion sd-jwt/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![godoc ssi-sdk](https://img.shields.io/badge/godoc-ssi--sdk-blue)](https://pkg.go.dev/github.com/TBD54566975/ssi-sdk/sd-jwt)
[![go version 1.22.1](https://img.shields.io/badge/go_version-1.22.1-brightgreen)](https://golang.org/)
[![go version 1.22.2](https://img.shields.io/badge/go_version-1.22.2-brightgreen)](https://golang.org/)
[![Go Report Card A+](https://goreportcard.com/badge/github.com/TBD54566975/ssi-sdk/sd-jwt)](https://goreportcard.com/report/github.com/TBD54566975/ssi-sdk/sd-jwt)
[![license Apache 2](https://img.shields.io/badge/license-Apache%202-black)](https://github.com/TBD54566975/ssi-sdk/blob/main/LICENSE)

Expand Down
33 changes: 33 additions & 0 deletions util/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"context"
"fmt"
"strings"

Expand All @@ -23,18 +24,36 @@ func LoggingError(err error) error {
return err
}

// LoggingCtxError is a utility to combine logging an error, and returning and error
func LoggingCtxError(ctx context.Context, err error) error {
logrus.WithContext(ctx).WithError(err).Error()
return err
}

// LoggingNewError is a utility to create an error from a message, log it, and return it as an error
func LoggingNewError(msg string) error {
err := errors.New(msg)
logrus.WithError(err).Error()
return err
}

// LoggingCtxNewError is a utility to create an error from a message, log it, and return it as an error
func LoggingCtxNewError(ctx context.Context, msg string) error {
err := errors.New(msg)
logrus.WithContext(ctx).WithError(err).Error()
return err
}

// LoggingNewErrorf is a utility to create an error from a formatted message, log it, and return it as an error
func LoggingNewErrorf(msg string, args ...any) error {
return LoggingNewError(fmt.Sprintf(msg, args...))
}

// LoggingCtxNewErrorf is a utility to create an error from a formatted message, log it, and return it as an error
func LoggingCtxNewErrorf(ctx context.Context, msg string, args ...any) error {
return LoggingCtxNewError(ctx, fmt.Sprintf(msg, args...))
}

// LoggingErrorMsg is a utility to combine logging an error, and returning and error with a message
func LoggingErrorMsg(err error, msg string) error {
logrus.WithError(err).Error(SanitizeLog(msg))
Expand All @@ -44,11 +63,25 @@ func LoggingErrorMsg(err error, msg string) error {
return errors.Wrap(err, msg)
}

// LoggingCtxErrorMsg is a utility to combine logging an error, and returning and error with a message
func LoggingCtxErrorMsg(ctx context.Context, err error, msg string) error {
logrus.WithContext(ctx).WithError(err).Error(SanitizeLog(msg))
if err == nil {
return errors.New(msg)
}
return errors.Wrap(err, msg)
}

// LoggingErrorMsgf is a utility to combine logging an error, and returning and error with a formatted message
func LoggingErrorMsgf(err error, msg string, args ...any) error {
return LoggingErrorMsg(err, fmt.Sprintf(msg, args...))
}

// LoggingCtxErrorMsgf is a utility to combine logging an error, and returning and error with a formatted message
func LoggingCtxErrorMsgf(ctx context.Context, err error, msg string, args ...any) error {
return LoggingCtxErrorMsg(ctx, err, fmt.Sprintf(msg, args...))
}

// SanitizeLog prevents certain classes of injection attacks before logging
// https://codeql.github.com/codeql-query-help/go/go-log-injection/
func SanitizeLog(log string) string {
Expand Down

0 comments on commit b1b9218

Please sign in to comment.