newError creates a new error message with a detailed error message. The message will be prefixed with the contents of the supplied error type. Additionally, more errors, that provide more context can be supplied which will be appended to the message. This makes use of Go 1.20's possibility to includ
(message string, err error, more ...error)
| 69 | // |
| 70 | // "token is unverifiable: no keyfunc was provided" |
| 71 | func newError(message string, err error, more ...error) error { |
| 72 | var format string |
| 73 | var args []any |
| 74 | if message != "" { |
| 75 | format = "%w: %s" |
| 76 | args = []any{err, message} |
| 77 | } else { |
| 78 | format = "%w" |
| 79 | args = []any{err} |
| 80 | } |
| 81 | |
| 82 | for _, e := range more { |
| 83 | format += ": %w" |
| 84 | args = append(args, e) |
| 85 | } |
| 86 | |
| 87 | err = fmt.Errorf(format, args...) |
| 88 | return err |
| 89 | } |
no outgoing calls