Skip to content

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

Merged
merged 4 commits into from
Jun 18, 2021
Merged

add back --retries flag #61

merged 4 commits into from
Jun 18, 2021

Conversation

umbynos
Copy link
Contributor

@umbynos umbynos commented Jun 17, 2021

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

@umbynos umbynos added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Jun 17, 2021
@umbynos umbynos requested a review from a team June 17, 2021 16:25
@umbynos umbynos self-assigned this Jun 17, 2021
// Exit if something went wrong but after printing
if err != nil {
os.Exit(errorcodes.ErrGeneric)
if err == nil {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

@silvanocerza
Copy link
Contributor

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:

var err error
for retry := 0; retry <= int(retries); retry++ {
    err = doTheThingsYouGottaDo(params)
    if err == nil {
        break
    }
}

if err != nil {
    // Tell the user and exit with error code
}

// Success

@umbynos umbynos merged commit 3aa8ec1 into main Jun 18, 2021
@umbynos umbynos deleted the umbynos/retry branch June 18, 2021 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants