-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor defer-close with error handling #378
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw some details that need handing;
Additionally, I would like to avoid using caution.CloseAndReportError
for scenarios without defer
, it does nonstandard error handling, and it may be a little convoluted to read. We can talk about a replacement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not really like that most of this refactoring is introducing named return values for non-trivial functions. It makes functions harder to read, and without an IDE highlighting it is difficult to verify that a return value name is not shadowed in a nested scope.
But I do understand that this seems to be a requirement imposed by the caution
package, and alternatives might be even more cumbersome.
However, I would like to ask to reconsider the naming and placement of the function IfErrorAddContext
as addressed in the comments. Please have a look.
61af49f
to
851efe7
Compare
94bcf0b
to
469c960
Compare
…requested in review
469c960
to
1f78e22
Compare
|
||
return nil | ||
// Close will resets terminal mode. | ||
caution.CloseAndReportError(&err, prompt.Stdin, "failed to reset terminal input") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this case is not defered, close can be called using normal procedures.
@@ -117,5 +118,7 @@ func (tt *index) scanPatternVariant(pos uint8, variant common.Hash, start uint64 | |||
break | |||
} | |||
} | |||
onMatched(nil) | |||
if _, err := onMatched(nil); err != nil { | |||
log.Warn("searchParallel", "err", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the first time i saw this line, i dont really know what to do with it.
The search algorithm will look for something not returning an error and producing errors may be the intended use.
The context we add to warn is not good.
- Write a complete sentence in warn: "error produced during parallel search"
- Add a comment explaining the issue, so that the problem is understood in case this line turns too verbose (which could affect performance of some hot region)
@HerbertJordan @kjezek do you know what this code is about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is the implementation of the log-filter feature. You can send RPC queries to the service asking for log messages listing a given set of topics. This function is searching for those and does a call-back on onMatched
for each element and, as it looks like, a final one passing a nil
to indicate that all matches have been reported and that there are no more.
The only time this function is actually used is in line 94 above, where onMatched
returns an error if, for instance, the execution context is canceled. Another option is that the consumer of the match failed to consume it, which seems to be ignored, as shown in line 116.
I guess the best option here, matching the action in line 116, is to simply ignore the error.
@@ -81,9 +82,9 @@ func makeEngine(chaindataDir string, cfg Configs) (*abft.Lachesis, *vecmt.Index, | |||
} | |||
defer func() { | |||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// }
func ExecuteAndReportError(err *error, f func() error, message string) {
fErr := f()
if fErr != nil {
*err = errors.Join(*err, fmt.Errorf("%s: %w", message, fErr))
}
}
this if is superfluous.
@@ -117,5 +118,7 @@ func (tt *index) scanPatternVariant(pos uint8, variant common.Hash, start uint64 | |||
break | |||
} | |||
} | |||
onMatched(nil) | |||
if _, err := onMatched(nil); err != nil { | |||
log.Warn("searchParallel", "err", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is the implementation of the log-filter feature. You can send RPC queries to the service asking for log messages listing a given set of topics. This function is searching for those and does a call-back on onMatched
for each element and, as it looks like, a final one passing a nil
to indicate that all matches have been reported and that there are no more.
The only time this function is actually used is in line 94 above, where onMatched
returns an error if, for instance, the execution context is canceled. Another option is that the consumer of the match failed to consume it, which seems to be ignored, as shown in line 116.
I guess the best option here, matching the action in line 116, is to simply ignore the error.
Please, Add one deferred error missing : |
moved to 0xsoniclabs/sonic#7 |
This PR contributes to https://github.com/Fantom-foundation/sonic-admin/issues/90
This PR adds real life use cases of both functions provided the caution package to properly handler errors in case of
defer
andclose
.This PR fixes some of the unhandled errors reported by the external audit. Most (if not all) of them are from either
defer close
patterns or similar cleanups or unhandled close errors.Test list to verify we don't have double closes (or other errors) and panic now because error is no longer ignored:
make test