Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

Improve error message for empty containers and tasks #11

Merged

Conversation

pameck
Copy link
Contributor

@pameck pameck commented Jun 30, 2018

Fixes #4
It was assumed the containers were always defined in the config file, but when only the name of the container is defined, Jackson converts it to an entry with null as the value.

containers:
  my-container:

This PR checks whether the container exists before transforming it to prevent the NullPointerException and produce a more user friendly error message.

@charleskorn
Copy link
Collaborator

Awesome, thanks @pameck, I'll take a look now.

Copy link
Collaborator

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

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

Looks good to me, there are just a couple of small comments.

@@ -39,7 +51,6 @@ data class ConfigurationFile(
if (pathResolver.relativeTo.root == pathResolver.relativeTo) {
throw ConfigurationException("No project name has been given explicitly, but the configuration file is in the root directory and so a project name cannot be inferred.")
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please revert this whitespace change?

@@ -56,6 +56,7 @@ class ConfigurationLoader(
}

Files.newInputStream(path, StandardOpenOption.READ).use {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please revert this whitespace change?

}

private fun fromFileToContainerConfiguration(containerName: String, fileContainerConfig: ContainerFromFile, pathResolver: PathResolver): Container {
if (fileContainerConfig == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is awful behaviour from Jackson... it really shouldn't be providing a null value here for something that can't be null. Not much we can do about that though, and it's already been reported at FasterXML/jackson-module-kotlin#144. (This makes me wonder where else we need to cover this case...)

It also means the compiler gives a warning about this condition (https://travis-ci.org/charleskorn/batect/builds/398475902#L577), because it should theoretically never be true. Could you perhaps make fileContainerConfig nullable (ie. ContainerFromFile? rather than ContainerFromFile) so that the compiler warning goes away?

@pameck
Copy link
Contributor Author

pameck commented Jul 1, 2018

@charleskorn thanks for the Kotlin tip on the nullable stuff, all fixed and the blank spaces reverted.

Don't merge it just yet, I'll add the check for tasks too on this PR.

@pameck
Copy link
Contributor Author

pameck commented Jul 1, 2018

@charleskorn re-review. I added the check for empty tasks as well.

@charleskorn charleskorn changed the title Improve error message for empty container Improve error message for empty containers and tasks Jul 1, 2018
@charleskorn charleskorn merged commit 0651af6 into batect:master Jul 1, 2018
@charleskorn
Copy link
Collaborator

Thanks @pameck, looks perfect.

@pameck pameck deleted the improve-error-message-for-empty-container branch April 10, 2019 11:06
charleskorn added a commit that referenced this pull request Dec 23, 2020
…ith an image that uses a non-default syntax.

The output previously looked something like (note output for #3 and #4):

#1 [internal] load remote build context
#1 DONE

#2 copy /context /
#2 DONE

#3 resolve image config for docker.io/docker/dockerfile:1.1-experimental
#3 ...

#4 docker-image://docker.io/docker/dockerfile:1.1-experimental@sha256:de85b2f3a3e8a2f7fe48e8e84a65f6fdd5cd5183afa6412fff9caa6871649c44
#4 ...

#5 [internal] load metadata for docker.io/library/ruby:2.7.2
#5 DONE

#6 [ 1/12] FROM docker.io/library/ruby:2.7.2
#6 DONE

#7 [ 2/12] RUN mkdir -p /tools
#7 CACHED

#8 [ 3/12] COPY health-check.sh /tools
#8 CACHED

#9 [ 4/12] RUN mkdir -p /app
#9 CACHED

#10 [ 5/12] COPY app/Gemfile app/Gemfile.lock /app/
#10 CACHED

#11 [ 6/12] WORKDIR /app
#11 CACHED

#12 [ 7/12] RUN bundle config set deployment true
#12 CACHED

#13 [ 8/12] RUN bundle config set without development
#13 CACHED

#14 [ 9/12] RUN bundle install
#14 CACHED

#15 [10/12] COPY app/config.ru /app
#15 CACHED

#16 [11/12] COPY app/bin /app/bin
#16 CACHED

#17 [12/12] COPY app/lib /app/lib
#17 ...

#3 resolve image config for docker.io/docker/dockerfile:1.1-experimental
#3 DONE

#4 docker-image://docker.io/docker/dockerfile:1.1-experimental@sha256:de85b2f3a3e8a2f7fe48e8e84a65f6fdd5cd5183afa6412fff9caa6871649c44
#4 CACHED

#17 [12/12] COPY app/lib /app/lib
#17 CACHED

#18 exporting to image
#18 exporting layers: done
#18 writing image sha256:ace2572ab366a9153b23ccc0667cc6163a32a3cbb96bfef237a25c68005699a6: done
#18 naming to docker.io/library/batect-sample-ruby-international-transfers-service: done
#18 DONE
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants