-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from spiegel-im-spiegel/new-error-handling
Add new error handler
- Loading branch information
Showing
17 changed files
with
373 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
language: go | ||
|
||
go: | ||
- "1.11.x" | ||
- "1.12" | ||
|
||
env: | ||
global: | ||
|
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 |
---|---|---|
|
@@ -8,26 +8,6 @@ | |
|
||
See [go.mod](https://github.com/spiegel-im-spiegel/mklink/blob/master/go.mod) file. | ||
|
||
### Module Requirement Graph | ||
|
||
``` | ||
$ go mod graph | ||
github.com/spiegel-im-spiegel/mklink github.com/PuerkitoBio/[email protected] | ||
github.com/spiegel-im-spiegel/mklink github.com/atotto/[email protected] | ||
github.com/spiegel-im-spiegel/mklink github.com/inconshreveable/[email protected] | ||
github.com/spiegel-im-spiegel/mklink github.com/mattn/[email protected] | ||
github.com/spiegel-im-spiegel/mklink github.com/pkg/[email protected] | ||
github.com/spiegel-im-spiegel/mklink github.com/spf13/[email protected] | ||
github.com/spiegel-im-spiegel/mklink github.com/spf13/[email protected] | ||
github.com/spiegel-im-spiegel/mklink github.com/spiegel-im-spiegel/[email protected] | ||
github.com/spiegel-im-spiegel/mklink golang.org/x/[email protected] | ||
github.com/spiegel-im-spiegel/mklink golang.org/x/[email protected] | ||
github.com/spiegel-im-spiegel/[email protected] github.com/mattn/[email protected] | ||
github.com/PuerkitoBio/[email protected] github.com/andybalholm/[email protected] | ||
github.com/PuerkitoBio/[email protected] golang.org/x/[email protected] | ||
github.com/andybalholm/[email protected] golang.org/x/[email protected] | ||
``` | ||
|
||
## Usage | ||
|
||
```go | ||
|
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
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
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,30 @@ | ||
package errs | ||
|
||
import ( | ||
errors "golang.org/x/xerrors" | ||
) | ||
|
||
func Cause(err error) error { | ||
for { | ||
unwrap := errors.Unwrap(err) | ||
if unwrap == nil { | ||
return err | ||
} | ||
err = unwrap | ||
} | ||
} | ||
|
||
/* Copyright 2019 Spiegel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ |
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,38 @@ | ||
package errs | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCause(t *testing.T) { | ||
testCases := []struct { | ||
err error | ||
cause error | ||
}{ | ||
{err: nil, cause: nil}, | ||
{err: ErrNoImplement, cause: ErrNoImplement}, | ||
{err: Wrap(ErrNoImplement, "wrapping error"), cause: ErrNoImplement}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
res := Cause(tc.err) | ||
if res != tc.cause { | ||
t.Errorf("Cause in \"%v\" == \"%v\", want \"%v\"", tc.err, res, tc.cause) | ||
} | ||
} | ||
} | ||
|
||
/* Copyright 2019 Spiegel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ |
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,38 @@ | ||
package errs | ||
|
||
import "fmt" | ||
|
||
//Num is error number for CVSS | ||
type Num int | ||
|
||
const ( | ||
ErrNullPointer Num = iota + 1 | ||
ErrNoImplement | ||
) | ||
|
||
var errMessage = map[Num]string{ | ||
ErrNullPointer: "Null reference instance", | ||
ErrNoImplement: "This style is not implementation", | ||
} | ||
|
||
func (n Num) Error() string { | ||
if s, ok := errMessage[n]; ok { | ||
return s | ||
} | ||
return fmt.Sprintf("unknown error (%d)", int(n)) | ||
} | ||
|
||
/* Copyright 2019 Spiegel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ |
Oops, something went wrong.