{"record":{"id":"ecfc8541b6bba221","repo":"slimtoolkit/slim","slug":"when-using-json-array-syntax-arrays-must-be-compr","errorCode":null,"errorMessage":"when using JSON array syntax, arrays must be comprised of strings only","messagePattern":"when using JSON array syntax, arrays must be comprised of strings only","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/docker/dockerfile/ast/line_parsers.go","lineNumber":53,"sourceCode":"\nfunc ofnve(context, message string) OldFormatNameValError {\n\treturn OldFormatNameValError{\n\t\tNameValError: nve(context, \"\", message),\n\t}\n}\n\ntype NewFormatNameValError struct {\n\tNameValError\n}\n\nfunc nfnve(context, data, message string) NewFormatNameValError {\n\treturn NewFormatNameValError{\n\t\tNameValError: nve(context, data, message),\n\t}\n}\n\nvar (\n\tErrDockerfileNotStringArray = errors.New(\"when using JSON array syntax, arrays must be comprised of strings only\")\n)\n\n// ignore the current argument. This will still leave a command parsed, but\n// will not incorporate the arguments into the ast.\nfunc parseIgnore(rest string, d *Directive) (*Node, map[string]bool, error) {\n\treturn &Node{}, nil, nil\n}\n\n// used for onbuild. Could potentially be used for anything that represents a\n// statement with sub-statements.\n//\n// ONBUILD RUN foo bar -> (onbuild (run foo bar))\nfunc parseSubCommand(rest string, d *Directive) (*Node, map[string]bool, error) {\n\tif rest == \"\" {\n\t\treturn nil, nil, nil\n\t}\n\n\tchild, err := newNodeFromLine(rest, d)","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/docker/dockerfile/ast/line_parsers.go#L35-L71","documentation":"ErrDockerfileNotStringArray is returned by the Dockerfile AST JSON line parsers (parseJSON, parseMaybeJSON, parseMaybeJSONToList) when an instruction that uses the JSON array form (e.g., CMD, ENTRYPOINT, ADD/COPY) contains a JSON array whose elements are not all strings. Docker requires exec-form arrays like [\"a\", \"b\"]; numeric or boolean elements are invalid.","triggerScenarios":"Writing CMD [1, 2] or ENTRYPOINT [true] in a Dockerfile and parsing it; parseMaybeJSONToList/parseMaybeJSON encountering arrays with non-string JSON values.","commonSituations":"Copy-pasted CMD arrays with unquoted numbers; programmatic Dockerfile generation emitting JSON with numeric values; typos dropping quotes around strings.","solutions":["Quote every element of the JSON array so all elements are strings","Remove non-string elements from the array","Use shell form (no brackets) if you don't need exec-form, e.g., CMD echo hello","Validate generated Dockerfiles with a linter before building"],"exampleFix":"# before\nCMD [1, \"-c\"]\n# after\nCMD [\"1\", \"-c\"]","handlingStrategy":"validation","validationCode":"// Go: ensure all array elements are strings before emitting JSON exec-form\nelems := []any{1, \"-c\"}\nfor _, e := range elems {\n    if _, ok := e.(string); !ok {\n        return fmt.Errorf(\"exec-form arrays must contain strings only\")\n    }\n}","typeGuard":"func isStringArray(v []any) bool {\n    for _, e := range v {\n        if _, ok := e.(string); !ok { return false }\n    }\n    return len(v) > 0\n}","tryCatchPattern":"node, flags, err := parseMaybeJSON(rest, d)\nif err != nil {\n    if errors.Is(err, ast.ErrDockerfileNotStringArray) {\n        // lint: report line and suggest quoting all array elements\n    }\n    return err\n}","preventionTips":["Always quote elements in exec-form arrays: [\"1\", \"-c\"]","Lint Dockerfiles in CI to catch non-string array elements","Prefer shell form when arguments are not a strict string list"],"tags":["dockerfile","parsing","json","go"],"backgroundTag":"dockerfile-json-array-type","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}