-
-
Notifications
You must be signed in to change notification settings - Fork 17
add back --retries
flag
#61
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
Conversation
cli/firmware/flash.go
Outdated
// Exit if something went wrong but after printing | ||
if err != nil { | ||
os.Exit(errorcodes.ErrGeneric) | ||
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.
Is this here only as a "belt and suspenders" measure in case there was some missed error handling in the code?
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.
Actually, this condition is here because it allows breaking from the retry loop. Not sure if this can be handled better...
After every error in the loop there's a continue statement that allows to start from the next iteration of the loop in case something is wrong
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.
After every error in the loop there's a continue statement that allows to start from the next iteration of the loop in case something is wrong
And for that reason, err
should never have any value other than nil
if this condition is reached, right?
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.
Correct
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 forgot the continue statement here https://github.com/arduino/FirmwareUploader/pull/61/files#diff-9bcc47c1909291c8177f70e16def7a94afe0d6c3fb6c937a8f2ccc91432b8aecR233
Thanks a lot @per1234
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.
OK, I'm mostly just trying to make sure I understand the code. Since it should never be other than nil
if the code is working correctly, I was wondering if a better "belt and suspenders" approach wouldn't be to panic:
if err !=nil{
panic(fmt.Sprintf("Unhandled error: %s", err))
}
break
I generally just throw in a panic to handle situations that should never occur unless something is broken in the code. It's not clear to me whether it would be beneficial to make the code resilient to this condition, since it could mask a bug.
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.
Well that behavior is present here.
At the end of the specified numbers of retries the program exits
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.
Yes, but that's a different situation from an unhandled error.
Anyway, I am happy with it as is. I think the retries are a very nice improvement. I always wish AVRDUDE had this option.
This solution certainly works and I like it, but I feel like it could be done in a clearer way if you extract the logic into a function so you can do something like this:
|
Add
--retries
flag just like in #24.We removed this behavior during the refactoring.
Basically, the FirmwareUploader tries to update the firmware 9 times in a row (by default). Sometimes there could be some failings because of programmer out of sync, serial port closing etc… With this flag, the process should be more reliable