Skip to content

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

Merged

Conversation

yangcao77
Copy link
Contributor

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

Signed-off-by: Stephanie <[email protected]>
@yangcao77 yangcao77 force-pushed the 397-validatorChecksImportAttributes branch 2 times, most recently from e62b6f1 to 565f6e0 Compare April 29, 2021 18:38
@yangcao77 yangcao77 force-pushed the 397-validatorChecksImportAttributes branch from 565f6e0 to a22cea8 Compare April 29, 2021 18:54
Copy link
Contributor

@amisevsk amisevsk left a 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 👍

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()
Copy link
Contributor

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:

Suggested change
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:

Suggested change
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"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@@ -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)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

}

func (e *InvalidCommandTypeError) Error() string {
return fmt.Sprintf("command %s type is invalid", e.commandId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Sprintf("command %s type is invalid", e.commandId)
return fmt.Sprintf("command %s has invalid type", e.commandId)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

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()
Copy link
Contributor

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")

Copy link
Contributor Author

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

@yangcao77 yangcao77 force-pushed the 397-validatorChecksImportAttributes branch from 16269b2 to 7cc978e Compare May 6, 2021 15:51
Copy link
Contributor

@amisevsk amisevsk left a comment

Choose a reason for hiding this comment

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

LGTM

@openshift-ci-robot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@yangcao77 yangcao77 merged commit 39103b3 into devfile:main May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants