You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Capture yet more bad defer / recover patterns (#719)
* Yet more bad defer / recover patterns
`recover()` is an eternal font of excitement.
* demonstrating another flavor of failure
* removing leftover code
* update documentation
* removes test not related to the rule itself
Co-authored-by: chavacava <[email protected]>
Copy file name to clipboardExpand all lines: RULES_DESCRIPTIONS.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -233,12 +233,14 @@ _Configuration_: N/A
233
233
## defer
234
234
235
235
_Description_: This rule warns on some common mistakes when using `defer` statement. It currently alerts on the following situations:
236
+
236
237
| name | description |
237
238
|------|-------------|
238
239
| call-chain| even if deferring call-chains of the form `foo()()` is valid, it does not helps code understanding (only the last call is deferred)|
239
240
|loop | deferring inside loops can be misleading (deferred functions are not executed at the end of the loop iteration but of the current function) and it could lead to exhausting the execution stack |
240
241
| method-call| deferring a call to a method can lead to subtle bugs if the method does not have a pointer receiver|
241
242
| recover | calling `recover` outside a deferred function has no effect|
243
+
| immediate-recover | calling `recover` at the time a defer is registered, rather than as part of the deferred callback. e.g. `defer recover()` or equivalent.|
242
244
| return | returning values form a deferred function has no effect|
243
245
244
246
These gotchas are described [here](https://blog.learngoprogramming.com/gotchas-of-defer-in-go-1-8d070894cb01)
0 commit comments