Skip to content

Commit

Permalink
examples: replace errors.Join with fmt.Errorf for go1.18 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
brandondyck committed Sep 9, 2024
1 parent 517e8a6 commit 391017f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
18 changes: 8 additions & 10 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,22 +303,20 @@ func ExampleErrorContains() {

func ExampleErrorIs() {
e1 := errors.New("e1")
e2 := errors.New("e2")
e3 := errors.New("e3")
errorChain := fmt.Errorf("%w%w%w", e1, e2, e3)
ErrorIs(t, errorChain, e2)
e2 := fmt.Errorf("e2: %w", e1)
e3 := fmt.Errorf("e3: %w", e2)
ErrorIs(t, e3, e1)
// Output:
}

func ExampleErrorAs() {
e1 := errors.New("e1")
e2 := FakeError("foo")
e3 := errors.New("e3")
errorChain := fmt.Errorf("%w%w%w", e1, e2, e3)
e1 := FakeError("e1")
e2 := fmt.Errorf("e2: %w", e1)
e3 := fmt.Errorf("e3: %w", e2)
var target FakeError
ErrorAs(t, errorChain, &target)
ErrorAs(t, e3, &target)
fmt.Println(target.Error())
// Output: foo
// Output: e1
}

func ExampleFalse() {
Expand Down
18 changes: 8 additions & 10 deletions must/examples_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 391017f

Please sign in to comment.