-
Notifications
You must be signed in to change notification settings - Fork 0
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 #3 from morikuni/failure-support
Support using with failure v2
- Loading branch information
Showing
6 changed files
with
58 additions
and
0 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
github.com/morikuni/failure/v2 v2.0.0-20230512003104-6bb497ead261 h1:Rqq1Kh/HMFt8YZFeW5jopA+l2wjV2+tMcouxbwuMxqs= | ||
github.com/morikuni/failure/v2 v2.0.0-20230512003104-6bb497ead261/go.mod h1:tHod902kOvu2+09OAbzPMrE4B8fIc+M/2kl/UI3mDQI= | ||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= | ||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= |
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,8 @@ | ||
package internal | ||
|
||
type failureKey bool | ||
|
||
const ( | ||
_key failureKey = true | ||
FailureKey = _key | ||
) |
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,17 @@ | ||
package mlangfailure | ||
|
||
import ( | ||
"github.com/morikuni/failure/v2" | ||
|
||
"github.com/morikuni/go-mlang" | ||
"github.com/morikuni/go-mlang/internal" | ||
) | ||
|
||
const ( | ||
Key = internal.FailureKey | ||
) | ||
|
||
func MessageOf(err error) mlang.Message { | ||
m, _ := failure.ValueAs[mlang.Message](err, Key) | ||
return m | ||
} |
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,20 @@ | ||
package mlangfailure | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/morikuni/failure/v2" | ||
|
||
"github.com/morikuni/go-mlang" | ||
) | ||
|
||
func TestMessageOf(t *testing.T) { | ||
err := failure.Unexpected("unexpected", mlang.Dict[string]{1: "one"}) | ||
m := MessageOf(err) | ||
if m == nil { | ||
t.Fatal("m is nil") | ||
} | ||
if m.MustGet(1) != "one" { | ||
t.Errorf("got %v, want %v", m.MustGet(1), "one") | ||
} | ||
} |