{"record":{"id":"978a9d10ce35c23b","repo":"slimtoolkit/slim","slug":"invalid-dockerfile","errorCode":null,"errorMessage":"invalid Dockerfile","messagePattern":"invalid Dockerfile","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/docker/dockerfile/parser/parser.go","lineNumber":17,"sourceCode":"// Package parser implements a Dockerfile parser\npackage parser\n\nimport (\n\t\"errors\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/slimtoolkit/slim/pkg/docker/dockerfile/ast\"\n\t\"github.com/slimtoolkit/slim/pkg/docker/dockerfile/spec\"\n\t\"github.com/slimtoolkit/slim/pkg/docker/instruction\"\n)\n\nvar (\n\tErrInvalidDockerfile = errors.New(\"invalid Dockerfile\")\n)\n\n//TODO:\n//* support incremental, partial and instruction level parsing\n//* support parsing from reader and from string\n\nfunc FromFile(fpath string) (*spec.Dockerfile, error) {\n\tfo, err := os.Open(fpath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tdefer fo.Close()\n\n\tastParsed, err := ast.Parse(fo)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/docker/dockerfile/parser/parser.go#L1-L35","documentation":"ErrInvalidDockerfile is a sentinel error in the dockerfile parser package indicating the Dockerfile input could not be parsed as a valid Dockerfile. It is returned by FromFile when parsing a Dockerfile from disk fails because the file is empty, unreadable, or structurally invalid. The parser cannot extract any usable instruction stream from it.","triggerScenarios":"Calling dockerfile/parser FromFile with a path that points to an empty file, a non-Dockerfile text file, or a file that fails AST-level parsing.","commonSituations":"Pointing build tooling at the wrong path (e.g. a directory or a .dockerignore), a Dockerfile deleted or truncated by CI, or a Dockerfile with unsupported syntax from a newer builder version.","solutions":["Verify the file at the given path exists, is non-empty, and is actually a Dockerfile (starts with a valid instruction like FROM).","Run 'docker build' or a linter on the same Dockerfile to confirm syntax validity independently.","Check that your tooling passes the Dockerfile path, not the build-context directory, to FromFile.","Regenerate or restore the Dockerfile from version control if it was truncated or corrupted."],"exampleFix":"// before\nast, err := parser.FromFile(ctx, \"./build\")\n// after\nast, err := parser.FromFile(ctx, \"./Dockerfile\")","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil || info.IsDir() || info.Size() == 0 {\n    return fmt.Errorf(\"dockerfile missing or empty: %s\", path)\n}\n// optional: sniff first line for FROM/ARG/escape directive","typeGuard":null,"tryCatchPattern":"if _, err := parser.FromFile(ctx, path); err != nil {\n    if errors.Is(err, parser.ErrInvalidDockerfile) {\n        // surface path + first bytes for diagnosis\n    }\n    return err\n}","preventionTips":["Always pass a file path, not a directory, to the parser.","Verify the file is non-empty before parsing.","Validate Dockerfile syntax in CI with a linter or dry-run build.","Restore Dockerfiles from VCS rather than generating ad hoc."],"tags":["dockerfile","parsing","input-validation"],"backgroundTag":"invalid-dockerfile","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}