{"record":{"id":"2d5769303d4957a3","repo":"slimtoolkit/slim","slug":"invalid-context-directory","errorCode":null,"errorMessage":"invalid context directory","messagePattern":"invalid context directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/builder/image_builder.go","lineNumber":22,"sourceCode":"\t\"bytes\"\n\t\"errors\"\n\t\"fmt\"\n\t\"path/filepath\"\n\t\"strings\"\n\n\t\"github.com/slimtoolkit/slim/pkg/app/master/config\"\n\t\"github.com/slimtoolkit/slim/pkg/consts\"\n\t\"github.com/slimtoolkit/slim/pkg/docker/dockerfile\"\n\t\"github.com/slimtoolkit/slim/pkg/util/fsutil\"\n\n\tdocker \"github.com/fsouza/go-dockerclient\"\n\tlog \"github.com/sirupsen/logrus\"\n)\n\n//todo: move/refactor this to be a \"pkg/imagebuilder\" engine\n\nvar (\n\tErrInvalidContextDir = errors.New(\"invalid context directory\")\n)\n\n// BasicImageBuilder creates regular container images\ntype BasicImageBuilder struct {\n\tShowBuildLogs bool\n\tBuildOptions  docker.BuildImageOptions\n\tAPIClient     *docker.Client\n\tBuildLog      bytes.Buffer\n}\n\n// ImageBuilder creates new optimized container images\ntype ImageBuilder struct {\n\tBasicImageBuilder\n\tRepoName       string\n\tAdditionalTags []string\n\tID             string\n\tEntrypoint     []string\n\tCmd            []string","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/builder/image_builder.go#L4-L40","documentation":"ErrInvalidContextDir is thrown by pkg/app/master/builder/image_builder.go when the directory given as a Docker build context is not usable — it does not exist or is not a valid build context. NewBasicImageBuilder / the docker build flow validates the context directory before sending it to the Docker daemon, since building requires a readable context containing a Dockerfile.","triggerScenarios":"Calling dockerutils/build via NewBasicImageBuilder with BuildImageOptions.ContextDir pointing to a non-existent path, a file instead of a directory, or a directory without read permission.","commonSituations":"Typos in the --build-path/context-dir flag; running docker-slim from a different working directory than expected; CI checkouts that did not create the context dir; pointing at a Dockerfile file instead of its parent directory.","solutions":["Verify the ContextDir value passed to NewBasicImageBuilder exists and is a directory (os.Stat, MkdirAll if needed)","Check file permissions on the directory so the process can read it","Run the tool from the directory you intend to use as the build context, or pass an absolute path"],"exampleFix":"// before\nopts := docker.BuildImageOptions{ContextDir: \"./buid-context\"}\n// after\nif _, err := os.Stat(\"./build-context\"); err != nil {\n\tos.MkdirAll(\"./build-context\", 0755)\n}\nopts := docker.BuildImageOptions{ContextDir: \"./build-context\"}","handlingStrategy":"validation","validationCode":"info, err := os.Stat(ctxDir)\nif err != nil || !info.IsDir() {\n\treturn fmt.Errorf(\"build context %q is not a directory\", ctxDir)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always stat the context directory before invoking the builder","Use absolute paths for ContextDir in scripts/CI","Ensure the directory contains a Dockerfile"],"tags":["docker","build-context","filesystem"],"backgroundTag":"invalid-build-context","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}