-
Notifications
You must be signed in to change notification settings - Fork 1.6k
✨ (CLI/Api): Add IfNotExistsAction to machinery for optional file handling #4967
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,13 +237,21 @@ func doTemplate(t Template) ([]byte, error) { | |
func (s Scaffold) updateFileModel(i Inserter, models map[string]*File) error { | ||
m, err := s.loadPreviousModel(i, models) | ||
if err != nil { | ||
// TODO(kubebuilder/issues/4960): Create Machinery implementation to allow defining IfNotExistsAction | ||
// If the file path starts with test/, warn and skip | ||
// Workaround to allow projects be backwards compatible with previous versions | ||
if strings.HasPrefix(i.GetPath(), "test/") { | ||
log.Warn("Skipping missing test file", "file_path", i.GetPath()) | ||
log.Warn("The code fragments will not be inserted.") | ||
return nil | ||
if os.IsNotExist(err) { | ||
if withOptionalBehavior, ok := i.(HasIfNotExistsAction); ok { | ||
switch withOptionalBehavior.GetIfNotExistsAction() { | ||
case IgnoreFile: | ||
log.Warn("Skipping missing file", "file", i.GetPath()) | ||
log.Warn("The code fragments will not be inserted.") | ||
return nil | ||
case ErrorIfNotExist: | ||
return err | ||
default: | ||
return err | ||
} | ||
} | ||
// If inserter doesn't implement HasIfNotExistsAction, return the original error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment indicates that if the inserter doesn't implement HasIfNotExistsAction, the original error should be returned, but the code will actually fall through to line 256 which wraps the error in a different format. This inconsistency between comment and implementation could lead to confusion about error handling behavior. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this comment okay? |
||
return err | ||
} | ||
return fmt.Errorf("failed to load previous model for %s: %w", i.GetPath(), err) | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.