{"record":{"id":"476d20d68d22a79d","repo":"kubernetes/kops","slug":"unable-to-remap-a-nil-url","errorCode":null,"errorMessage":"unable to remap a nil URL","messagePattern":"unable to remap a nil URL","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/assets/builder.go","lineNumber":322,"sourceCode":"\t\treturn image\n\t}\n\n\tdigest, err := imageDigestResolver(image)\n\tif err != nil {\n\t\tklog.Warningf(\"failed to digest image %q: %s\", image, err)\n\t\treturn image\n\t}\n\n\treturn image + \"@\" + digest\n}\n\n// RemapFile returns a remapped URL for the file, if AssetsLocation is defined.\n// It is returns in a FileAsset, alongside the SHA hash of the file.\n// The SHA hash is is knownHash is provided, and otherwise will be found first by\n// checking the canonical URL against our well-known hashes, and failing that via download.\nfunc (a *AssetBuilder) RemapFile(canonicalURL *url.URL, knownHash *hashing.Hash) (*FileAsset, error) {\n\tif canonicalURL == nil {\n\t\treturn nil, fmt.Errorf(\"unable to remap a nil URL\")\n\t}\n\n\tfileAsset := &FileAsset{\n\t\tDownloadURL:  canonicalURL,\n\t\tCanonicalURL: canonicalURL,\n\t}\n\n\tif a.assetsLocation != nil && a.assetsLocation.FileRepository != nil {\n\t\tnormalizedFile, err := a.remapURL(canonicalURL)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tif canonicalURL.Host != normalizedFile.Host {\n\t\t\tfileAsset.DownloadURL = normalizedFile\n\t\t\tklog.V(4).Infof(\"adding remapped file: %q\", fileAsset.DownloadURL.String())\n\t\t}\n\t}","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/assets/builder.go#L304-L340","documentation":"AssetBuilder.RemapFile rejects a nil canonical URL argument before doing any work. Callers must pass a parsed *url.URL for the file they want remapped; a nil indicates the caller failed to construct the URL (e.g. url.Parse failed earlier or was skipped).","triggerScenarios":"Passing nil as canonicalURL to RemapFile — typically when a values source produced an empty/missing base URL and the caller skipped url.Parse instead of failing early.","commonSituations":"Config where the kubernetes download URL or CNI URL env/option is empty, so the code composes a nil URL; a version string lookup returning empty causing url.Parse of \"\" that callers treated as ok.","solutions":["Ensure the caller always parses and passes a valid *url.URL; check the option/env that supplies the base URL.","Add an early check at the call site and return a clearer error naming the missing setting.","For nodeup/kops config, verify KubernetesVersion and file URLs are fully specified."],"exampleFix":"// before\nu, err := url.Parse(fileURL) // fileURL == \"\" -> treated as ok\nfileAsset, err := a.RemapFile(u, hash)\n// after\nif fileURL == \"\" {\n\treturn nil, fmt.Errorf(\"file url is not defined\")\n}\nu, err := url.Parse(fileURL)\nif err != nil {\n\treturn nil, err\n}\nfileAsset, err := a.RemapFile(u, hash)","handlingStrategy":"validation","validationCode":"if canonicalURL == nil {\n\treturn fmt.Errorf(\"file URL is not configured; check kubernetes/cni download URL settings\")\n}","typeGuard":"func isValidURL(u *url.URL) bool { return u != nil && u.Scheme != \"\" && u.Host != \"\" }","tryCatchPattern":"fileAsset, err := assetBuilder.RemapFile(canonicalURL, knownHash)\nif err != nil {\n\tif strings.Contains(err.Error(), \"unable to remap a nil URL\") {\n\t\treturn fmt.Errorf(\"caller bug: canonical URL for %s was nil; check base URL config\", name)\n\t}\n\treturn err\n}","preventionTips":["Never skip url.Parse error handling — a nil/zero URL should abort early.","Assert base URL config (versions, mirrors) is non-empty before building assets.","Unit-test asset URL construction with empty config to catch nil propagation."],"tags":["assets","nil-pointer","url"],"backgroundTag":"nil-url-argument","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}