-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daisuke Maki
committed
Oct 25, 2024
1 parent
c5278c6
commit 911467a
Showing
4 changed files
with
131 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package jwk | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
var cpe = &continueError{} | ||
|
||
// ContinueError returns an opaque error that can be returned | ||
// when a `KeyParser`, `KeyImporter`, or `KeyExporter` cannot handle the given payload, | ||
// but would like the process to continue with the next handler. | ||
func ContinueError() error { | ||
return cpe | ||
} | ||
|
||
type continueError struct{} | ||
|
||
func (e *continueError) Error() string { | ||
return "continue parsing" | ||
} | ||
|
||
// IsContinueError returns true if the given error is a ContinueError. | ||
func IsContinueError(err error) bool { | ||
return errors.Is(err, &continueError{}) | ||
} | ||
|
||
type importError struct { | ||
error | ||
} | ||
|
||
func (e importError) Unwrap() error { | ||
return e.error | ||
} | ||
|
||
func (importError) Is(err error) bool { | ||
_, ok := err.(importError) | ||
return ok | ||
} | ||
|
||
func importerr(f string, args ...any) error { | ||
return importError{fmt.Errorf(`jwk.Import: `+f, args...)} | ||
} | ||
|
||
var errDefaultImportError = importError{errors.New(`import error`)} | ||
|
||
func ImportError() error { | ||
return errDefaultImportError | ||
} | ||
|
||
type parseError struct { | ||
error | ||
} | ||
|
||
func (e parseError) Unwrap() error { | ||
return e.error | ||
} | ||
|
||
func (parseError) Is(err error) bool { | ||
_, ok := err.(parseError) | ||
return ok | ||
} | ||
|
||
func bparseerr(prefix string, f string, args ...any) error { | ||
return parseError{fmt.Errorf(prefix+`: `+f, args...)} | ||
} | ||
|
||
func parseerr(f string, args ...any) error { | ||
return bparseerr(`jwk.Parse`, f, args...) | ||
} | ||
|
||
func rparseerr(f string, args ...any) error { | ||
return bparseerr(`jwk.ParseReader`, f, args...) | ||
} | ||
|
||
func sparseerr(f string, args ...any) error { | ||
return bparseerr(`jwk.ParseString`, f, args...) | ||
} | ||
|
||
var errDefaultParseError = parseError{errors.New(`parse error`)} | ||
|
||
func ParseError() error { | ||
return errDefaultParseError | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters