From 70cd2aa16dd712514c52109943abb2b42fe66cd1 Mon Sep 17 00:00:00 2001 From: Harri Lainio Date: Mon, 7 Aug 2023 18:35:58 +0300 Subject: [PATCH] Logf works without argument --- try/out.go | 13 ++++++++----- try/result2_test.go | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/try/out.go b/try/out.go index b6fc059..675ab26 100644 --- a/try/out.go +++ b/try/out.go @@ -40,14 +40,17 @@ type ( // // error sending response: UDP not listening func (o *Result) Logf(a ...any) *Result { - if o.Err == nil || len(a) == 0 { + if o.Err == nil { return o } - f, isFormat := a[0].(string) - if isFormat { - s := fmt.Sprintf(f+": %v", append(a[1:], o.Err)...) - _ = handler.LogOutput(2, s) + s := o.Err.Error() + if len(a) != 0 { + f, isFormat := a[0].(string) + if isFormat { + s = fmt.Sprintf(f+": %v", append(a[1:], o.Err)...) + } } + _ = handler.LogOutput(2, s) return o } diff --git a/try/result2_test.go b/try/result2_test.go index d1b1527..9853cdd 100644 --- a/try/result2_test.go +++ b/try/result2_test.go @@ -21,7 +21,7 @@ func ExampleResult2_Logf() { err2.SetLogTracer(os.Stdout) countSomething := func(s1, s2 string) (int, int) { - r := try.Out2(convTwoStr(s1, s2)).Logf("not number").Def2(10, 10) + r := try.Out2(convTwoStr(s1, s2)).Logf().Def2(10, 10) v1, v2 := r.Val1, r.Val2 return v1 + v2, v2 } @@ -29,6 +29,6 @@ func ExampleResult2_Logf() { num1, num2 := countSomething("WRONG", "2") fmt.Printf("results: %d, %d", num1, num2) err2.SetLogTracer(nil) - // Output: not number: testing run example: strconv.Atoi: parsing "WRONG": invalid syntax + // Output: testing run example: strconv.Atoi: parsing "WRONG": invalid syntax // results: 20, 10 }