{"record":{"id":"ceb7a90cbb3ef14f","repo":"docker/cli","slug":"invalid-platform-w-ceb7a9","errorCode":null,"errorMessage":"invalid platform: %w","messagePattern":"invalid platform: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/image/save.go","lineNumber":62,"sourceCode":"\tflags := cmd.Flags()\n\n\tflags.StringVarP(&opts.output, \"output\", \"o\", \"\", \"Write to a file, instead of STDOUT\")\n\tflags.StringSliceVar(&opts.platform, \"platform\", []string{}, `Save only the given platform(s). Formatted as a comma-separated list of \"os[/arch[/variant]]\" (e.g., \"linux/amd64,linux/arm64/v8\")`)\n\t_ = flags.SetAnnotation(\"platform\", \"version\", []string{\"1.48\"})\n\n\t_ = cmd.RegisterFlagCompletionFunc(\"platform\", completion.Platforms())\n\treturn cmd\n}\n\n// runSave performs a save against the engine based on the specified options\nfunc runSave(ctx context.Context, dockerCLI command.Cli, opts saveOptions) error {\n\tvar options []client.ImageSaveOption\n\n\tplatformList := []ocispec.Platform{}\n\tfor _, p := range opts.platform {\n\t\tpp, err := platforms.Parse(p)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid platform: %w\", err)\n\t\t}\n\t\tplatformList = append(platformList, pp)\n\t}\n\tif len(platformList) > 0 {\n\t\toptions = append(options, client.ImageSaveWithPlatforms(platformList...))\n\t}\n\n\tvar output io.Writer\n\tif opts.output == \"\" {\n\t\tif dockerCLI.Out().IsTerminal() {\n\t\t\treturn errors.New(\"cowardly refusing to save to a terminal. Use the -o flag or redirect\")\n\t\t}\n\t\toutput = dockerCLI.Out()\n\t} else {\n\t\twriter, err := atomicwriter.New(opts.output, 0o600)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to save image: %w\", err)\n\t\t}","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/image/save.go#L44-L80","documentation":"Returned by runSave (save.go:62) when platforms.Parse rejects one of the --platform values for 'docker image save'. Identical validator and flag semantics to load/history: a comma-separated list of 'os[/arch[/variant]]' tokens, each parsed in turn; the first failure aborts.","triggerScenarios":"Running 'docker image save --platform <bad> -o out.tar <image>' where any element is malformed (missing OS, extra slashes, empty tokens). Save then proceeds to request only the validated platforms from the daemon.","commonSituations":"Passing arch-only values ('--platform amd64'); wrong separator or casing; copy-pasting a platform string that includes OS features or an unexpected variant component; trailing comma yielding an empty platform token.","solutions":["Format each platform as 'os/arch[/variant]': '--platform linux/amd64'.","Strip malformed tokens from the comma-separated list.","Confirm available platforms: 'docker buildx imagetools inspect <image>'.","Drop --platform to save all platforms."],"exampleFix":"# before\ndocker image save --platform amd64 -o out.tar nginx\n# after\ndocker image save --platform linux/amd64 -o out.tar nginx","handlingStrategy":"validation","validationCode":"// Validate each platform in a comma-separated --platform list before saving.\nfunc validatePlatforms(list []string) error {\n\tfor _, p := range list {\n\t\tif _, err := platforms.Parse(p); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid platform %q: %w\", p, err)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(); err != nil {\n\tif strings.Contains(err.Error(), \"invalid platform\") {\n\t\t// correct the platform list and re-run save\n\t}\n}","preventionTips":["Format every element as os/arch[/variant].","Use 'docker buildx imagetools inspect' to confirm available platforms.","Omit --platform to save all platforms."],"tags":["image","save","platform","validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}