{"record":{"id":"19a4418be756ee6b","repo":"docker/cli","slug":"bad-format-for-links-val","errorCode":null,"errorMessage":"bad format for links: {val}","messagePattern":"bad format for links: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/opts.go","lineNumber":381,"sourceCode":"\t}\n\tnano := cpu.Mul(cpu, big.NewRat(1e9, 1))\n\tif !nano.IsInt() {\n\t\treturn 0, errors.New(\"value is too precise\")\n\t}\n\treturn nano.Num().Int64(), nil\n}\n\n// ParseLink parses and validates the specified string as a link format (name:alias)\nfunc ParseLink(val string) (string, string, error) {\n\tif val == \"\" {\n\t\treturn \"\", \"\", errors.New(\"empty string specified for links\")\n\t}\n\t// We expect two parts, but restrict to three to allow detecting invalid formats.\n\tarr := strings.SplitN(val, \":\", 3)\n\n\t// TODO(thaJeztah): clean up this logic!!\n\tif len(arr) > 2 {\n\t\treturn \"\", \"\", errors.New(\"bad format for links: \" + val)\n\t}\n\t// TODO(thaJeztah): this should trim the \"/\" prefix as well??\n\tif len(arr) == 1 {\n\t\treturn val, val, nil\n\t}\n\t// This is kept because we can actually get a HostConfig with links\n\t// from an already created container and the format is not `foo:bar`\n\t// but `/foo:/c1/bar`\n\tif strings.HasPrefix(arr[0], \"/\") {\n\t\t// TODO(thaJeztah): clean up this logic!!\n\t\t_, alias := path.Split(arr[1])\n\t\treturn arr[0][1:], alias, nil\n\t}\n\treturn arr[0], arr[1], nil\n}\n\n// ValidateLink validates that the specified string has a valid link format (containerName:alias).\nfunc ValidateLink(val string) (string, error) {","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/opts.go#L363-L399","documentation":"Thrown by opts.ParseLink when the input contains more than one colon (SplitN with limit 3 yields 3 parts), which is not a valid \"name:alias\" link. Docker link syntax allows at most one colon separating container name from alias; anything with extra colons (e.g. an IPv6-ish or scheme:host:port value) is malformed.","triggerScenarios":"Calling opts.ParseLink(\"a:b:c\") or any string with two or more colons. Passing --link with a value like \"redis:6379:db\".","commonSituations":"Accidentally pasting a URL or host:port spec into --link, or concatenating fields that introduce an extra colon. Legacy links also support a \"/name:/container/alias\" form, which is handled separately, but three plain colon-separated segments are not.","solutions":["Reduce the value to at most two colon-separated parts (name:alias).","If you meant a single name with no alias, drop the colon entirely.","Strip any URL scheme or port suffix that introduced the extra colon."],"exampleFix":"// before\nname, alias, err := opts.ParseLink(\"redis:6379:db\")\n// after\nname, alias, err := opts.ParseLink(\"redis:db\")","handlingStrategy":"validation","validationCode":"if strings.Count(link, \":\") > 1 {\n    return fmt.Errorf(\"link %q has too many colons; expected name:alias\", link)\n}\nname, alias, err := opts.ParseLink(link)","typeGuard":null,"tryCatchPattern":"name, alias, err := opts.ParseLink(link)\nif err != nil {\n    return err\n}","preventionTips":["Validate link strings contain at most one colon before parsing.","Avoid pasting URLs or host:port specs into --link."],"tags":["links","legacy","validation","opts"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}