Skip to content
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

Adds exception handling to ManifestPusher. #63

Merged
merged 19 commits into from
Feb 8, 2018
Merged

Conversation

coollog
Copy link
Contributor

@coollog coollog commented Feb 6, 2018

Fixes #40 .

Specifically, it lets the user know what might have caused a 404 (a bad tag is most likely). Note that there is no validation for the configuration here.

@coollog coollog requested a review from loosebazooka February 6, 2018 21:16
@coollog coollog added this to the 0.1.1 milestone Feb 6, 2018
*/
throw new RegistryErrorExceptionBuilder(getActionDescription(), httpResponseException)
.addReason(
"repository name not known to registry (make sure that you are using a valid tag - tags cannot contain backslashes)")
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this message can be confusing. Since we're talking about a bad repository name, but then asking them to correct their tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the wording to "...perhaps you are using an invalid tag..." - does that sound better?

@@ -90,6 +92,9 @@ RegistryErrorExceptionBuilder addReason(String reason) {
}

RegistryErrorException build() {
// Provides a feedback channel.
errorMessageBuilder.append(
" | If this is a bug, please file an issue at https://github.com/google/jib/issues/new");
Copy link
Member

Choose a reason for hiding this comment

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

Can you put github.com/google/jib.... in a ProjectInfo file or something static that we reference everywhere?

@coollog coollog mentioned this pull request Feb 6, 2018
*/
throw new RegistryErrorExceptionBuilder(getActionDescription(), httpResponseException)
.addReason(
"repository name not known to registry (perhaps you are using an invalid tag - tags cannot contain backslashes)")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the repository name available here? If so it could be in the error message and you could tell for sure if it contains slashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried this on GCR and it produces a correct error message already (about using an invalid tag - this error message will show up as part of the wrapped HttpResponseException), but on ECR, it simply gives a 404 and not in the expected Docker registry 404 format.

Copy link
Member

Choose a reason for hiding this comment

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

If we know their tag here already on our own, from imageTag, can we just tell them that their tag contains backslashes if it does?

Copy link
Member

Choose a reason for hiding this comment

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

and if it doesn't, then we print the registry from registryEndpointProperties.getImageName() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If their imageTag contains backslashes, we might want to just tell them that before entering the build process. Maybe we should just add a warning in the Maven plugin if the tag configuration contains backslashes?

Copy link
Member

Choose a reason for hiding this comment

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

If tags with \ are illegal, perhaps manifest pusher might want to throw an illegal arugment exception in the constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it might be good to keep ManifestPusher decoupled from any logic about the formatting of the image tag, since that is specific to the implementation of different Docker registries. Also, an IllegalArgumentException would mean an additional logic in BuildImageMojo to catch that exception and give the user a more meaningful error message. I added some validation in the BuildImageMojo that validates its configuration - currently it just logs some errors but doesn't fail, but perhaps it should fail? I can also remove this custom error message in ManifestPusher since the one in the Mojo is more helpful.

// 'tag' must not contain backslashes.
if (tag.indexOf('/') >= 0) {
getLog().error("'tag' cannot contain backslashes");
shouldFail = true;
Copy link
Member

Choose a reason for hiding this comment

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

this tag check can probably just go at the end, and we can remove the shouldFail flag.

@coollog coollog merged commit db6196d into master Feb 8, 2018
@coollog coollog deleted the prevent-invalid-tag branch February 8, 2018 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants