9
9
package main
10
10
11
11
import (
12
+ "flag"
12
13
"fmt"
13
14
"io"
14
15
"os"
16
+ "strconv"
15
17
16
18
"github.com/lainio/err2"
17
19
"github.com/lainio/err2/assert"
@@ -90,22 +92,23 @@ func OrgCopyFile(src, dst string) (err error) {
90
92
return nil
91
93
}
92
94
93
- func CallRecur (d int ) (err error ) {
95
+ func CallRecur (d int ) (ret int , err error ) {
94
96
defer err2 .Handle (& err )
95
97
96
98
return doRecur (d )
97
99
}
98
100
99
- func doRecur (d int ) (err error ) {
101
+ func doRecur (d int ) (ret int , err error ) {
100
102
d --
101
103
if d >= 0 {
102
104
// Keep below to show how asserts work
103
- assert .NotZero (d )
105
+ // assert.NotZero(d)
104
106
// Comment out the above assert statement to simulate runtime-error
105
- fmt .Println (10 / d )
106
- return doRecur (d )
107
+ ret = 10 / d
108
+ fmt .Println (ret )
109
+ //return doRecur(d)
107
110
}
108
- return fmt .Errorf ("root error" )
111
+ return ret , fmt .Errorf ("root error" )
109
112
}
110
113
111
114
func doPlayMain () {
@@ -136,7 +139,7 @@ func doPlayMain() {
136
139
doDoMain ()
137
140
//try.To(doMain())
138
141
139
- println ("___ happy ending ===" )
142
+ fmt . Println ("___ happy ending ===" )
140
143
}
141
144
142
145
func doDoMain () {
@@ -163,13 +166,20 @@ func doMain() (err error) {
163
166
// Both source and destination don't exist
164
167
//try.To(OrgCopyFile("/notfound/path/file.go", "/notfound/path/file.bak"))
165
168
166
- // 2nd argument is empty
167
- try .To (OrgCopyFile ("main.go" , "" ))
168
-
169
- // Next fn demonstrates how error and panic traces work, comment out all
170
- // above CopyFile calls to play with:
171
- try .To (CallRecur (1 ))
169
+ // to play with real args:
170
+ try .To (CopyFile (flag .Arg (0 ), flag .Arg (1 )))
171
+
172
+ if len (flag .Args ()) > 0 {
173
+ // Next fn demonstrates how error and panic traces work, comment out all
174
+ // above CopyFile calls to play with:
175
+ argument := try .To1 (strconv .Atoi (flag .Arg (0 )))
176
+ ret := try .To1 (CallRecur (argument ))
177
+ fmt .Println ("ret val:" , ret )
178
+ } else {
179
+ // 2nd argument is empty to assert
180
+ try .To (OrgCopyFile ("main.go" , "" ))
181
+ }
172
182
173
- println ("=== you cannot see this ===" )
183
+ fmt . Println ("=== you cannot see this ===" )
174
184
return nil
175
185
}
0 commit comments