-
Notifications
You must be signed in to change notification settings - Fork 64
validator checks import attributes #420
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
validator checks import attributes #420
Conversation
Signed-off-by: Stephanie <[email protected]>
Signed-off-by: Stephanie <[email protected]>
Signed-off-by: Stephanie <[email protected]>
e62b6f1
to
565f6e0
Compare
… reference if any Signed-off-by: Stephanie <[email protected]>
565f6e0
to
a22cea8
Compare
Signed-off-by: Stephanie <[email protected]>
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.
Just a few comments, generally looks good 👍
pkg/validation/commands.go
Outdated
return fmt.Errorf("there should be exactly one default command, currently there is more than one default command") | ||
var commandsReference string | ||
for _, command := range defaultCommands { | ||
commandsReference += resolveErrorMessageWithImportAttributes(fmt.Errorf("; command: %s", command.Id), command.Attributes).Error() |
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.
I think fmt.Sprintf
might be cleaner here for formatting:
commandsReference += resolveErrorMessageWithImportAttributes(fmt.Errorf("; command: %s", command.Id), command.Attributes).Error() | |
commandsReference = fmt.Sprintf("%s; %s", commandsReference, resolveErrorMessageWithImportAttributes(fmt.Errorf("command: %s", command.Id), command.Attributes).Error() |
or we could accumulate to a []string
and use Join
:
commandsReference += resolveErrorMessageWithImportAttributes(fmt.Errorf("; command: %s", command.Id), command.Attributes).Error() | |
commandsReferenceList = append(commandsReferenceList, resolveErrorMessageWithImportAttributes(fmt.Errorf("command: %s", command.Id), command.Attributes).Error()) | |
//... | |
strings.Join(commandsReferenceList, "; ") |
This would avoid the need to format the message below with "default command%s"
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.
updated
pkg/validation/components.go
Outdated
@@ -103,7 +106,9 @@ func ValidateComponents(components []v1alpha2.Component) error { | |||
for componentName, volumeMountNames := range processedVolumeMounts { | |||
for _, volumeMountName := range volumeMountNames { | |||
if !processedVolumes[volumeMountName] { | |||
invalidVolumeMountsErr += fmt.Sprintf("\nvolume mount %s belonging to the container component %s", volumeMountName, componentName) | |||
missingVolumeMountErr := fmt.Errorf("\nvolume mount %s belonging to the container component %s", volumeMountName, componentName) |
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.
Outside the scope of this PR, but seeing fmt.Errorf("\nvolume
makes me feel like MissingVolumeMountError
should store errs: []string
rather than errMsg: string
.
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.
updated
pkg/validation/errors.go
Outdated
} | ||
|
||
func (e *InvalidCommandTypeError) Error() string { | ||
return fmt.Sprintf("command %s type is invalid", e.commandId) |
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.
return fmt.Sprintf("command %s type is invalid", e.commandId) | |
return fmt.Sprintf("command %s has invalid type", e.commandId) |
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.
updated
pkg/validation/projects.go
Outdated
errString += fmt.Sprintf("\nstarterProject %s should have at least one remote", starterProject.Name) | ||
starterProjectErr := fmt.Errorf("\nstarterProject %s should have at least one remote", starterProject.Name) | ||
newErr := resolveErrorMessageWithImportAttributes(starterProjectErr, starterProject.Attributes) | ||
errString += newErr.Error() |
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.
I think we should accumulate errors in []string
and use strings.Join(errList, "\n")
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.
updated. Also update all error concatenation to use []string & string join
Signed-off-by: Stephanie <[email protected]>
16269b2
to
7cc978e
Compare
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.
LGTM
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: amisevsk, yangcao77 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What does this PR do?
This PR checks import attributes before validator returns an error message to improve the error message shown
validator will check for the specific attribute before sending back the error message. If the attribute does not exist, the error message will be as what it currently has.
What issues does this PR fix or reference?
#397
Is your PR tested? Consider putting some instruction how to test your changes
Added unit tests
Docs PR