{"record":{"id":"46708440c81a3e56","repo":"slimtoolkit/slim","slug":"could-not-decode-command-q-w","errorCode":null,"errorMessage":"could not decode command %q: %w","messagePattern":"could not decode command %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/execution/standalone.go","lineNumber":106,"sourceCode":"\t}\n\n\tif err := encoder.Encode(evt); err != nil {\n\t\tlog.WithError(err).Warn(\"sensor: failed dumping event\")\n\t}\n}\n\n// TODO: Make this function return a list of commands.\nfunc readCommandFile(filename string) (command.StartMonitor, error) {\n\tvar cmd command.StartMonitor\n\n\tdata, err := os.ReadFile(filename)\n\tif err != nil {\n\t\treturn cmd, fmt.Errorf(\"could not read command file %q: %w\", filename, err)\n\t}\n\tdata = bytes.Split(data, []byte(\"\\n\"))[0]\n\n\tif err := json.Unmarshal(data, &cmd); err != nil {\n\t\treturn cmd, fmt.Errorf(\"could not decode command %q: %w\", string(data), err)\n\t}\n\n\t// The instrumented image will always have the ENTRYPOINT overwritten\n\t// by the instrumentor to make the sensor the PID1 process in the monitored\n\t// container.\n\t// The original ENTRYPOINT & CMD will be preserved as part of the\n\t// `commands.json` file. However, it's also possible to override the\n\t// CMD at runtime by supplying extra args to the `docker run` (or alike)\n\t// command. Sensor needs to be able to detect this and replace the\n\t// baked in CMD with the new list of args. For that, the instrumented image's\n\t// ENTRYPOINT has to contain a special separator value `--` denoting the end\n\t// of the sensor's flags sequence. Example:\n\t//\n\t// ENTRYPOINT [\"/path/to/sensor\", \"-m=standalone\", \"-c=/path/to/commands.json\", \"--\" ]\n\n\t// Note on CMD & ENTRYPOINT override: Historically, sensor used\n\t// AppName + AppArgs[] to start the target process. With the addition\n\t// of the standalone mode, the need for supporting Docker's original","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/execution/standalone.go#L88-L124","documentation":"After reading the first line of the command file, readCommandFile unmarshals it into a command.StartMonitor struct. If the JSON is malformed or does not match the struct, this error wraps the json.Unmarshal failure, echoing the offending data.","triggerScenarios":"Command file's first line is empty, truncated, contains invalid JSON, or has fields incompatible with command.StartMonitor (wrong types, unknown/mismatched schema).","commonSituations":"Instrumentor wrote a partial/older schema version of the command; file corrupted on write; the first line is a shell shebang or comment instead of JSON.","solutions":["Inspect the echoed data in the error and validate it as JSON (e.g. jq) to find the syntax/schema problem.","Ensure the instrumentor and sensor use compatible versions of the command.StartMonitor schema.","Regenerate the command file with the correct JSON StartMonitor payload as its first line."],"exampleFix":"// before (malformed first line)\n{\"command\":, \"args\":[]}\n// after (valid StartMonitor JSON)\n{\"command\":\"/usr/bin/app\",\"args\":[\"--port\",\"8080\"]}","handlingStrategy":"validation","validationCode":"func validateCommandFile(path string) error {\n    data, err := os.ReadFile(path)\n    if err != nil { return err }\n    first := bytes.Split(data, []byte(\"\\n\"))[0]\n    var probe map[string]interface{}\n    return json.Unmarshal(first, &probe)\n}","typeGuard":"func isJSONDecodeError(err error) bool {\n    var ue *json.UnmarshalTypeError\n    var se *json.SyntaxError\n    return errors.As(err, &ue) || errors.As(err, &se)\n}","tryCatchPattern":"exec, err := execution.NewStandalone(commandFile, eventFile, hook)\nif err != nil && strings.Contains(err.Error(), \"could not decode command\") {\n    log.Fatalf(\"command file contains invalid JSON: %v\", err)\n}","preventionTips":["Validate the command JSON with jq or a schema check in CI before deploying.","Ensure the first line of the file is the complete JSON payload (no shebang/comments).","Pin compatible versions of instrumentor and sensor so command.StartMonitor fields match.","Write the file atomically so readers never see partial JSON."],"tags":["json","parsing","schema-mismatch","configuration"],"backgroundTag":"json-decode-failed","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}