Skip to content

Commit 809b9aa

Browse files
committed
wrong number strings to bad number
1 parent e0eec58 commit 809b9aa

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

try/out.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func Out1[T any](v T, err error) *Result1[T] {
261261
//
262262
// or in some other cases, some of these would be desired action:
263263
//
264-
// x, y := try.Out2(convTwoStr(s1, s2)).Logf("wrong number").Catch(1, 2)
264+
// x, y := try.Out2(convTwoStr(s1, s2)).Logf("bad number").Catch(1, 2)
265265
// y := try.Out2(convTwoStr(s1, s2)).Handle().Val2
266266
func Out2[T any, U any](v1 T, v2 U, err error) *Result2[T, U] {
267267
return &Result2[T, U]{Val2: v2, Result1: Result1[T]{Val1: v1, Result: Result{Err: err}}}

try/out_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,27 @@ func ExampleResult1_Logf() {
8181
return try.Out1(strconv.Atoi(s)).Logf("not number").Catch(100)
8282
}
8383
num1 := countSomething("1")
84-
num2 := countSomething("WRONG")
84+
num2 := countSomething("BAD")
8585
fmt.Printf("results: %d, %d", num1, num2)
8686
err2.SetLogTracer(nil)
8787

88-
// Output: not number: strconv.Atoi: parsing "WRONG": invalid syntax
88+
// Output: not number: strconv.Atoi: parsing "BAD": invalid syntax
8989
// results: 1, 100
9090
}
9191

9292
func TestResult2_Logf(t *testing.T) {
9393
t.Parallel()
94-
// Set log tracing to stdout that we can see it in Example output. In
95-
// normal cases that would be a Logging stream or stderr.
96-
err2.SetLogTracer(os.Stdout)
9794

9895
convTwoStr := func(s1, s2 string) (_ int, _ int, err error) {
9996
defer err2.Handle(&err, nil)
10097

10198
return try.To1(strconv.Atoi(s1)), try.To1(strconv.Atoi(s2)), nil
10299
}
103100
countSomething := func(s1, s2 string) (int, int) {
104-
v1, v2 := try.Out2(convTwoStr(s1, s2)).Logf("wrong number").Catch(1, 2)
101+
v1, v2 := try.Out2(convTwoStr(s1, s2)).Logf("bad number").Catch(1, 2)
105102
return v1 + v2, v2
106103
}
107-
num1, num2 := countSomething("1", "err")
108-
fmt.Printf("results: %d, %d\n", num1, num2)
104+
num1, num2 := countSomething("1", "bad")
109105
test.RequireEqual(t, num2, 2)
110106
test.RequireEqual(t, num1, 3)
111107
}

try/result2_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func ExampleResult2_Logf() {
2626
return v1 + v2, v2
2727
}
2828
_, _ = countSomething("1", "2")
29-
num1, num2 := countSomething("WRONG", "2")
29+
num1, num2 := countSomething("BAD", "2")
3030
fmt.Printf("results: %d, %d", num1, num2)
3131
err2.SetLogTracer(nil)
32-
// Output: testing: run example: strconv.Atoi: parsing "WRONG": invalid syntax
32+
// Output: testing: run example: strconv.Atoi: parsing "BAD": invalid syntax
3333
// results: 20, 10
3434
}

0 commit comments

Comments
 (0)