{"record":{"id":"03b1a161fcd2f7f9","repo":"docker/cli","slug":"unable-to-read-inspect-data-w","errorCode":null,"errorMessage":"unable to read inspect data: %w","messagePattern":"unable to read inspect data: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/inspect/inspector.go","lineNumber":134,"sourceCode":"\t\t}\n\t\treturn i.tryRawInspectFallback(rawElement)\n\t}\n\ti.buffer.Write(buffer.Bytes())\n\ti.buffer.WriteByte('\\n')\n\treturn nil\n}\n\n// tryRawInspectFallback executes the inspect template with a raw interface.\n// This allows docker cli to parse inspect structs injected with Swarm fields.\nfunc (i *TemplateInspector) tryRawInspectFallback(rawElement []byte) error {\n\tvar raw any\n\tbuffer := new(bytes.Buffer)\n\trdr := bytes.NewReader(rawElement)\n\tdec := json.NewDecoder(rdr)\n\tdec.UseNumber()\n\n\tif err := dec.Decode(&raw); err != nil {\n\t\treturn fmt.Errorf(\"unable to read inspect data: %w\", err)\n\t}\n\n\ttmplMissingKey := i.tmpl.Option(\"missingkey=error\")\n\tif err := tmplMissingKey.Execute(buffer, raw); err != nil {\n\t\treturn fmt.Errorf(\"template parsing error: %w\", err)\n\t}\n\n\ti.buffer.Write(buffer.Bytes())\n\ti.buffer.WriteByte('\\n')\n\treturn nil\n}\n\n// Flush writes the result of inspecting all elements into the output stream.\nfunc (i *TemplateInspector) Flush() error {\n\tif i.buffer.Len() == 0 {\n\t\t_, err := io.WriteString(i.out, \"\\n\")\n\t\treturn err\n\t}","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/inspect/inspector.go#L116-L152","documentation":"Returned by `tryRawInspectFallback` (inspector.go:133-134) when `json.Decode(&raw)` fails on the raw inspect bytes. This path runs only after the typed template execution already failed, so the CLI tries to decode the raw payload as a generic interface; if that payload is not valid JSON (or is empty), decoding fails. The %w wraps the encoding/json error.","triggerScenarios":"A `getRef` implementation returns raw bytes that are not valid JSON while a custom `--format` template is used. Common in programmatically-driven inspect flows or when the daemon returns a truncated/corrupt response.","commonSituations":"Daemon returning a non-JSON error body, a proxy truncating the response, or a custom resource type whose raw form isn't JSON.","solutions":["Inspect without `--format` to confirm the raw response is valid: `docker inspect <ref>`.","Restart/reconnect to the daemon if responses are truncated.","Check for an intermediary (proxy, MITM) corrupting the response stream.","File a bug if the raw bytes are genuinely non-JSON for a supported resource."],"exampleFix":"# before\ndocker inspect --format '{{.X}}' <ref>   # raw payload not JSON\n# after\ndocker inspect <ref>                          # verify raw JSON first, then add --format","handlingStrategy":"validation","validationCode":"// validate raw inspect payload is JSON before templating\nvar probe any\nif err := json.Unmarshal(rawElement, &probe); err != nil {\n    return fmt.Errorf(\"raw inspect payload is not valid JSON; aborting template run: %w\", err)\n}","typeGuard":"func isJSON(b []byte) bool {\n    var v any\n    return json.Unmarshal(b, &v) == nil\n}","tryCatchPattern":"if err := inspector.Inspect(typed, raw); err != nil {\n    if strings.Contains(err.Error(), \"unable to read inspect data\") {\n        log.Warn(\"daemon returned non-JSON inspect data; retry without --format\")\n        return runInspectNoFormat(ref)\n    }\n    return err\n}","preventionTips":["Sanity-check daemon connectivity before inspecting.","Avoid custom proxies that may corrupt the response body.","Retry without --format to isolate data vs template errors."],"tags":["inspect","json","template","fallback","docker-cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}