Skip to content

Commit 4c79008

Browse files
committed
automigration quide
1 parent be238e6 commit 4c79008

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

scripts/README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ checking, which makes this so important but difficult. The `err2` package writes
2929
problems to `stderr` because it cannot panic in middle of the panicking. Note.
3030
This is only a legacy code problem. We are migration as you see :-)
3131

32+
#### Manual v0.9.40 Migration With Location List (nvim/vim)
33+
3234
Follow these steps check do you have migration needs for v0.9.40:
3335
1. [Set up Migration Environment](#set-up-migration-environment)
34-
1. Execute following command:
36+
1. Execute following command in your repo's root directory:
3537
```shell
36-
migr-name.sh todo_handle_func todo_catch_func
38+
migr-name.sh -ndv todo_handle_func todo_catch_func
3739
```
3840

41+
*Tip. If your repo is large and you have many migration changes see the next
42+
[semi-automatic guide](#semi-automatic-v0.9.40-migration).*
43+
3944
*Tip. You can execute that command from e.g. nvim/vim and you get your fix list.*
4045
```shell
4146
migr-name.sh todo_handle_func todo_catch_func > todo_list
@@ -46,10 +51,20 @@ nvim -q todo_list
4651
nvim -q <(migr-name.sh todo_handle_func todo_catch_func)
4752
```
4853

49-
**Note. We are still in middle to process check if we can make this migration
50-
automatic, at least semi-automatic. Probably we cannot do the same as with
51-
others because the error value setting isn't closure anymore where we can refer
52-
the `err` return variable directly.**
54+
#### Semi-Automatic v0.9.40 Migration
55+
56+
Follow these steps:
57+
1. [Set up Migration Environment](#set-up-migration-environment)
58+
1. Make sure that you haven't uncommitted changes in your repo and that you are
59+
in the branch where you want to make the changes.
60+
1. Execute following command in your repo's root directory:
61+
```shell
62+
migr-name.sh -ndv repl_handle_func repl_catch_func
63+
```
64+
1. Then continue with `build`, `test`, `lint`, etc. **And don't stop yet.**
65+
1. Use `git diff` or similar to skimming that all changes seem to be OK. Here
66+
you have an opportunity to start use new features of `err2` like logging.
67+
1. You are ready to commit changes.
5368

5469
### `assert.SetDefaultAsserter` -> `assert.SetDefault` and others in v0.9.1
5570

scripts/functions.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ clean() {
353353

354354
search_0_multi='(^\s*)(err)( :?= )((.|\n)*?)(\n)(\s*try\.To\(err\))'
355355
search_1_multi='(^\s*[\w\.]*)(, err)( :?= )([\s\S]*?)(\n)(\s*try\.To\(err\))'
356-
search_2_multi="(^\s*[\w\.]*, [\w\.]*)(, err)( :?= )([\s\S]*?)(\n)(\s*try\.To\(err\))"
357-
search_3_multi="(^\s*[\w\.]*, [\w\.]*, [\w\.]*)(, err)( :?= )([\s\S]*?)(\n)(\s*try\.To\(err\))"
356+
search_2_multi='(^\s*[\w\.]*, [\w\.]*)(, err)( :?= )([\s\S]*?)(\n)(\s*try\.To\(err\))'
357+
search_3_multi='(^\s*[\w\.]*, [\w\.]*, [\w\.]*)(, err)( :?= )([\s\S]*?)(\n)(\s*try\.To\(err\))'
358358

359359
# other tested versions, left here for debugging purposes
360360
#search_2_multi="(^\s*\w*, \w*)(, err)( :?= )([\s\S]*?)(\n)(\s*try\.To\(err\))"
@@ -460,14 +460,28 @@ todo_assert() {
460460
ag 'assert\.[DP]+\.'
461461
}
462462

463+
search_handle_multi='(^\s*)(defer err2\.Handle\(&err, func\(\) \{)([\s\S]*?)(^\s*\}\)$)'
464+
463465
todo_handle_func() {
464-
dlog "searching old error handlers"
465-
ag 'err2\.Handle\(&err, func\(\)'
466+
vlog "searching old error Handlers"
467+
ag "$search_handle_multi"
468+
}
469+
470+
repl_handle_func() {
471+
vlog "replacing old error Handlers"
472+
check_commit "$search_handle_multi" '\1defer err2.Handle(&err, func(err error) error {\3\1\treturn err\n\1})'
466473
}
467474

475+
search_catch_multi='(^\s*)(defer err2\.Catch\(func\(err error\) \{)([\s\S]*?)(^\s*\}\)$)'
476+
468477
todo_catch_func() {
469-
dlog "searching old error handlers"
470-
ag 'err2\.Catch\(func\(err error\) \{'
478+
vlog "searching old error Catchers"
479+
ag "$search_catch_multi"
480+
}
481+
482+
repl_catch_func() {
483+
vlog "replacing old error Catchers"
484+
check_commit "$search_catch_multi" '\1defer err2.Catch(err2.Err(func(err error) {\3\1}))'
471485
}
472486

473487
lint() {

try/notfound_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func ExampleIsNotFound1() {
2828
err2.SetErrorTracer(nil)
2929

3030
find := func(key int) string {
31-
defer err2.Catch(func(err error) {
31+
defer err2.Catch(err2.Err(func(err error) {
3232
fmt.Println("ERROR:", err)
33-
})
33+
}))
3434
notFound, value := try.IsNotFound1(FindObject(key))
3535
if notFound {
3636
return fmt.Sprintf("cannot find key (%d)", key)

0 commit comments

Comments
 (0)