-
Notifications
You must be signed in to change notification settings - Fork 5
feat: internalise command
#90
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
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.
Nice lower deltas idea 💯
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.
Nice 👍
Just 2-3 tiny comments on error wrappings (I'm a fanatic of error wrappings ❌ 📓 )
| // Since we're not creating, the zero perm/mode is ignored. | ||
| f, err := os.OpenFile(fileName, os.O_TRUNC|os.O_WRONLY, 0) //nolint:gosec // Variable file is under our direct control in go:generate | ||
| if err != nil { | ||
| return fmt.Errorf("os.OpenFile(%q, [write-only, truncate]): %v", fileName, 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.
nit always wrap errors with %w (aka wrap), not %v; also regarding error wrapping, I would suggest something a bit less code-focused such as:
| return fmt.Errorf("os.OpenFile(%q, [write-only, truncate]): %v", fileName, err) | |
| return fmt.Errorf("opening source file to override %q: %w", fileName, err) |
- The programmer when debugging could then easily find the relevant code
os.OpenFile(fileName, os.O_TRUNC|os.O_WRONLY, 0)so there is no need to wrap this information I think - the programmer does not need to maintain the error message wrap in case the function call
os.OpenFilechanges (just a general rule, it probably won't change much here)
| return fmt.Errorf("os.OpenFile(%q, [write-only, truncate]): %v", fileName, err) | ||
| } | ||
| if err := format.Node(f, fset, parsed); err != nil { | ||
| return fmt.Errorf("format.Node(%T): %v", parsed, 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.
same here 😉 I don't think having the parsed type (always *ast.File) is really useful, and we don't really want to log it out either 😄
| return fmt.Errorf("format.Node(%T): %v", parsed, err) | |
| return fmt.Errorf("formatting node to file: %w", err) |
| mode := parser.SkipObjectResolution | parser.ParseComments | ||
| parsed, err := parser.ParseFile(fset, fileName, nil, mode) | ||
| if err != nil { | ||
| return fmt.Errorf("parser.ParseFile(%q): %v", fileName, 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.
nit the wrapping is a bit misleading, especially since the ParseFile signature isn't the same. Why not just dumb old human-like wording as follows? Also wrap errors with %w not %v 😉
| return fmt.Errorf("parser.ParseFile(%q): %v", fileName, err) | |
| return fmt.Errorf("parsing source file %q: %w", fileName, err) |
Why this should be merged
Replaces #86. That approach couldn't be replicated for generated JSON marshalling, and this once also reduces the upstream delta.
How this works
AST manipulation of a specified file, which finds specified methods and modifies their names to be unexported.
How this was tested
Inspection of the output (
core/types/gen_header_rlp.goremains unchanged).