{"record":{"id":"d69d41deeba51d05","repo":"slimtoolkit/slim","slug":"error-reading-dockerignore-v","errorCode":null,"errorMessage":"Error reading .dockerignore: %v","messagePattern":"Error reading \\.dockerignore: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/docker/dockerignore/dockerignore.go","lineNumber":122,"sourceCode":"\t\tinvert := pattern[0] == '!'\n\t\tif invert {\n\t\t\tpattern = strings.TrimSpace(pattern[1:])\n\t\t}\n\t\tif len(pattern) > 0 {\n\t\t\tpattern = filepath.Clean(pattern)\n\t\t\tpattern = filepath.ToSlash(pattern)\n\t\t\tif len(pattern) > 1 && pattern[0] == '/' {\n\t\t\t\tpattern = pattern[1:]\n\t\t\t}\n\t\t}\n\t\tif invert {\n\t\t\tpattern = \"!\" + pattern\n\t\t}\n\n\t\texcludes = append(excludes, pattern)\n\t}\n\tif err := scanner.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"Error reading .dockerignore: %v\", err)\n\t}\n\treturn excludes, nil\n}\n\n//Docker's pattern matching\n\ntype patternMatcher struct {\n\tpatterns   []*pattern\n\texclusions bool\n}\n\nfunc newPatternMatcher(patterns []string) (*patternMatcher, error) {\n\tpm := &patternMatcher{\n\t\tpatterns: make([]*pattern, 0, len(patterns)),\n\t}\n\tfor _, p := range patterns {\n\t\t// Eliminate leading and trailing whitespace.\n\t\tp = strings.TrimSpace(p)","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/docker/dockerignore/dockerignore.go#L104-L140","documentation":"readPatterns (called by dockerignore.Load) scans a .dockerignore file; scanner.Err() reports any I/O or decoding failure encountered while reading. The error wraps the underlying scanner error, meaning the .dockerignore exists but could not be read (permissions, I/O error, invalid encoding).","triggerScenarios":"Calling dockerignore.Load (via readPatterns) on a .dockerignore file that is unreadable: permission denied mid-read, file replaced/deleted between open and scan, I/O device error, or invalid (non-UTF-8) bytes causing scanner failure.","commonSituations":"CI runners where the workspace .dockerignore has restrictive permissions; a .dockerignore that is a directory or a broken symlink opened then failing on read; rootless builds hitting permission issues after checkout with umask problems.","solutions":["Check file permissions on .dockerignore (chmod 644) and ensure the process user can read it.","Confirm the path is a regular file, not a directory or broken symlink, and re-create the file if it is corrupt.","Fix the underlying I/O issue (disk full, network mount failure) indicated by the wrapped %v detail, then retry."],"exampleFix":"// before\n-rw------- .dockerignore  (owned by root, build runs as ci)\n// after\nchmod 644 .dockerignore","handlingStrategy":"validation","validationCode":"fi, err := os.Stat(dockerignorePath)\nif err != nil || fi.IsDir() {\n\treturn fmt.Errorf(\".dockerignore missing or not a file\")\n}\nf, err := os.Open(dockerignorePath)\nif err != nil { return err }\nif _, err := f.Read(make([]byte, 1)); err != nil {\n\treturn fmt.Errorf(\".dockerignore unreadable: %w\", err)\n}\nf.Close()","typeGuard":null,"tryCatchPattern":"excludes, err := dockerignore.Load(path)\nif err != nil && strings.Contains(err.Error(), \"Error reading .dockerignore\") {\n\treturn fmt.Errorf(\"build context unusable: %w\", err)\n}","preventionTips":["chmod 644 .dockerignore in CI checkout steps","Ensure .dockerignore is a regular file, not a symlink to nowhere or a directory","Keep .dockerignore UTF-8 encoded and committed to the repo"],"tags":["dockerignore","file-io","docker","permissions"],"backgroundTag":"file-read-failed","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}