Skip to content

Add replaceraw#451

Open
JohnAZoidberg wants to merge 1 commit into
linuxboot:mainfrom
JohnAZoidberg:replaceraw
Open

Add replaceraw#451
JohnAZoidberg wants to merge 1 commit into
linuxboot:mainfrom
JohnAZoidberg:replaceraw

Conversation

@JohnAZoidberg
Copy link
Copy Markdown

I wanted to replace raw files like Intel VBT in firmware images. Very similar to replacepe32

I wanted to replace raw files like Intel VBT in firmware images.
Very similar to replacepe32

Signed-off-by: Daniel Schaefer <dhs@frame.work>
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 50.00000% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.79%. Comparing base (162b021) to head (bf6721a).

Files with missing lines Patch % Lines
pkg/visitors/replaceraw.go 50.00% 16 Missing and 4 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #451      +/-   ##
==========================================
+ Coverage   44.78%   44.79%   +0.01%     
==========================================
  Files         170      171       +1     
  Lines       12233    12273      +40     
==========================================
+ Hits         5478     5498      +20     
- Misses       5933     5949      +16     
- Partials      822      826       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@rminnich rminnich left a comment

Choose a reason for hiding this comment

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

This is great, you just need to change some of the error handling in code and test.

name string
newRaw []byte
match string
err string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

since we first wrote fiano, Go error handling picked up some of the nice bits from Rust.
SO: this err string should be err error

NewRaw: test.newRaw,
}
err = replace.Run(f)
if err == nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be ! errors.Is(err, test.err) and you can avoid the else in that case.

return errors.New("no matches found for replacement")
}
if len(find.Matches) > 1 {
return errors.New("multiple matches found! There can be only one. Use find to list all matches")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This errors.New should be
return ErrMultilpleMatches, which you can declare as an exported variable, with a commend, right before this function:
var ErrMultipleMatches = errors.New("multiple matches found! There can be only one. Use find to list all matches")


v.Matches = find.Matches
if len(find.Matches) == 0 {
return errors.New("no matches found for replacement")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You want to avoid errors.New in anything but a variable declaration, and you want to wrap standard errors for tests. And you might was well be as informative as possible.
return fmt.Errorf("no matches found for %v:%w", theThingYouAreTryingToMatchWhichICan'tSee, os.ErrNotexist)

then in your test, below, you can test for errors.Is(test.err), and test.err can be initialized to os.ErrNotExist, and now you're not string matching any more.
Thanks for this useful contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants