slimtoolkit/slim · error
when using JSON array syntax, arrays must be comprised of st
Error message
when using JSON array syntax, arrays must be comprised of strings only
What it means
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.
Source
Thrown at pkg/docker/dockerfile/ast/line_parsers.go:53
func ofnve(context, message string) OldFormatNameValError {
return OldFormatNameValError{
NameValError: nve(context, "", message),
}
}
type NewFormatNameValError struct {
NameValError
}
func nfnve(context, data, message string) NewFormatNameValError {
return NewFormatNameValError{
NameValError: nve(context, data, message),
}
}
var (
ErrDockerfileNotStringArray = errors.New("when using JSON array syntax, arrays must be comprised of strings only")
)
// ignore the current argument. This will still leave a command parsed, but
// will not incorporate the arguments into the ast.
func parseIgnore(rest string, d *Directive) (*Node, map[string]bool, error) {
return &Node{}, nil, nil
}
// used for onbuild. Could potentially be used for anything that represents a
// statement with sub-statements.
//
// ONBUILD RUN foo bar -> (onbuild (run foo bar))
func parseSubCommand(rest string, d *Directive) (*Node, map[string]bool, error) {
if rest == "" {
return nil, nil, nil
}
child, err := newNodeFromLine(rest, d)View on GitHub (pinned to 81940d17fa)
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
Example fix
# before CMD [1, "-c"] # after CMD ["1", "-c"]
Defensive patterns
Strategy: validation
Validate before calling
// Go: ensure all array elements are strings before emitting JSON exec-form
elems := []any{1, "-c"}
for _, e := range elems {
if _, ok := e.(string); !ok {
return fmt.Errorf("exec-form arrays must contain strings only")
}
} Type guard
func isStringArray(v []any) bool {
for _, e := range v {
if _, ok := e.(string); !ok { return false }
}
return len(v) > 0
} Try / catch
node, flags, err := parseMaybeJSON(rest, d)
if err != nil {
if errors.Is(err, ast.ErrDockerfileNotStringArray) {
// lint: report line and suggest quoting all array elements
}
return err
} Prevention
- 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
When it happens
Trigger: Writing CMD [1, 2] or ENTRYPOINT [true] in a Dockerfile and parsing it; parseMaybeJSONToList/parseMaybeJSON encountering arrays with non-string JSON values.
Common situations: Copy-pasted CMD arrays with unquoted numbers; programmatic Dockerfile generation emitting JSON with numeric values; typos dropping quotes around strings.
Related errors
- unknown instruction
- only one escape parser directive can be used
- invalid Dockerfile
- could not decode command %q: %w
- invalid ESCAPE '%s'. Must be ` or \
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/ecfc8541b6bba221.
Report an issue: GitHub.