Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Replace all fmt.Errorf with errors.Wrap and errors.Errorf #236

Closed
krasi-georgiev opened this issue Oct 28, 2020 · 15 comments · Fixed by #283 or #286
Closed

Replace all fmt.Errorf with errors.Wrap and errors.Errorf #236

krasi-georgiev opened this issue Oct 28, 2020 · 15 comments · Fixed by #283 or #286
Labels
difficulty: good first issue Good for newcomers help wanted Contributions are very wellcome priority: medium type: clean up making the code fit best practices

Comments

@krasi-georgiev
Copy link
Collaborator

No description provided.

@krasi-georgiev krasi-georgiev added help wanted Contributions are very wellcome difficulty: good first issue Good for newcomers type: clean up making the code fit best practices priority: medium labels Oct 28, 2020
@krasi-georgiev krasi-georgiev changed the title Where possible replace all fmt.Errorf with errors.Wrap Replace all fmt.Errorf with errors.Wrap and errors.Errorf Nov 18, 2020
@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 10.0779 TRB (281.17 USD @ $27.9/TRB) attached to it.

@developerfred
Copy link
Contributor

@themandalore
I'm interested in working on this issue, invite me through Gitcoin

my work plan is to make all the changes

@themandalore
Copy link
Contributor

@developerfred , sent. You're our space monkey with regards to testing out this whole gitcoin thing, so let me know if you need anything

@developerfred
Copy link
Contributor

@themandalore Thanks, perfect!

@themandalore
Copy link
Contributor

themandalore commented Nov 18, 2020

Looks like there's still some fmt.Errorf in httpRetriever.go and logConfig.go (the util package)
@developerfred

@developerfred
Copy link
Contributor

@themandalore I'll check here, thanks for letting me know.

@developerfred developerfred mentioned this issue Nov 18, 2020
2 tasks
@developerfred
Copy link
Contributor

@themandalore done.

@themandalore
Copy link
Contributor

Looks good, let me know the next steps with regard to gitcoin

@developerfred
Copy link
Contributor

@themandalore You can add me to the bounty, when I try to express interest I get an error. I reported to the team and I'm analyzing the Gitcoin code to see why.

my gitcoin user: @developerfred

@themandalore
Copy link
Contributor

@developerfred , I can't really do anything. I'll reach out to them, but if it takes more than a day or two, just reach back out and we'll close it and manually fix it

@developerfred
Copy link
Contributor

@themandalore perfect, i'm talking to them too.
They will fix it now, then the process is just to approve me and then pay.

@developerfred
Copy link
Contributor

@themandalore done, now you need to approve me on Gitcoin, for me to submit PR.

@krasi-georgiev
Copy link
Collaborator Author

krasi-georgiev commented Nov 18, 2020

Reopening as I had something else in mind.
We need to utilize errors.Wrap, errors.Wrapf and also remove the stutter words to improve the log messages. Words like - can't, error, failed should be removed as these will be repeated in the final log message.

Here are few examples of required changes:

errors.Errorf("file %s stat error: %v", historyPath, err)
changed to
errors.Wrapf(err,"stats for file: %v", historyPath)
alternative - but I am not a big fan of this one as error prone.
errors.Errors("stats for file: %v, err:%w", historyPath,err)

Note removing the error word - we don't needs it as this is clear and the final print message will include it twice.

Using errors.Wrap allows us to do error matching in the caller and it is generally more structured:
see: https://blog.golang.org/go1.13-errors, It mentioned the use of %w, but I am not a fan as it is quite error-prone. - it is easy to use %v and difficult to follow in PRs so I prefer using the wrap method.

In the caller, we can do something like if err == ErrNotFound(error matching by type) which is more difficult without using the wrap method.

errors.Errorf("failed to read psr file @ %s: %v", historyPath, err)
changed to
errors.Wrap(err,"read psr file:%v", historyPath)

please note again the removal of the word failed it is not needed. Also here we don't use Wrapf, but just Wrap

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 266 years from now.
Please review their action plans below:

1) developerfred has been approved to start work.

I would love to work on this issue, my work plan is to make all the replacements
2) janus has applied to start work (Funders only: approve worker | reject worker).

I have worked on Go projects before and I also have good linux skill to find and match words. I would take just hours to get this task done.
3) zyfrank has applied to start work (Funders only: approve worker | reject worker).

I'm familiar with go, I'd like to take this task
4) faith has applied to start work (Funders only: approve worker | reject worker).

I would be able replace all of them either manually or automatically.

Learn more on the Gitcoin Issue Details page.

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work for 10.0779 TRB (283.87 USD @ $28.16/TRB) has been submitted by:


Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
difficulty: good first issue Good for newcomers help wanted Contributions are very wellcome priority: medium type: clean up making the code fit best practices
Projects
None yet
4 participants