Commit 4607ace
committed
transport/ca/localca: New(): return error instead of calling os.Exit(1)
This code was added in 56dfed7, but
now has become the only use of github.com/kisom/goutils/assert, which
previously was used in tests, and now is archived (moved to a new module).
There were a couple of issues with this code;
The `assert.NoError` appears to have a bug; it accepts optional arguments,
but those are ignored; https://github.com/kisom/goutils/blob/v1.4.3/assert/assert.go#L90-L99
In this case, it meant that the additional information to describe the
error won't be printed.
Looking at the code (https://github.com/kisom/goutils/blob/v1.4.3/assert/assert.go#L35-L45),
it defaults (`GOTRACEBACK` anything other than "crash") using `os.Exit(1)`.
While (from the description), program execution MUST be terminated, there
are some downsides to using `os.Exit` here, as it terminates execution
immediately (which is desirable), but has no way to recover. While users
should NOT use the result in this case, they still may want to catch this
error (without terminating the program as a whole, which may be problematic
if this module is used as part of a service). `os.Exit` also does not execute
pending `defer` statements, which may still be desirable to handle state cleanup.
This patch changes the function to return an error instead, allowing the
caller to handle the error.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>1 parent cfd0e9a commit 4607ace
1 file changed
Lines changed: 10 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
150 | 152 | | |
151 | 153 | | |
152 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
153 | 157 | | |
154 | 158 | | |
155 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
156 | 162 | | |
157 | 163 | | |
158 | 164 | | |
| |||
0 commit comments