{"record":{"id":"216a5b5ae49a206d","repo":"GoogleContainerTools/skaffold","slug":"parsing-image-v-w","errorCode":null,"errorMessage":"parsing image %v: %w","messagePattern":"parsing image (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/hooks/build.go","lineNumber":40,"sourceCode":"\t\"fmt\"\n\t\"io\"\n\t\"path/filepath\"\n\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/docker\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest\"\n)\n\n// BuildRunner creates a new runner for pre-build and post-build lifecycle hooks\nfunc BuildRunner(d latest.BuildHooks, opts BuildEnvOpts) Runner {\n\treturn buildRunner{BuildHooks: d, opts: opts}\n}\n\n// NewBuildEnvOpts returns `BuildEnvOpts` required to create a `Runner` for build lifecycle hooks\nfunc NewBuildEnvOpts(a *latest.Artifact, image string, pushImage bool) (BuildEnvOpts, error) {\n\tref, err := docker.ParseReference(image)\n\tif err != nil {\n\t\treturn BuildEnvOpts{}, fmt.Errorf(\"parsing image %v: %w\", image, err)\n\t}\n\n\tw, err := filepath.Abs(a.Workspace)\n\tif err != nil {\n\t\treturn BuildEnvOpts{}, fmt.Errorf(\"determining build workspace directory for image %v: %w\", a.ImageName, err)\n\t}\n\treturn BuildEnvOpts{\n\t\tImage:        image,\n\t\tPushImage:    pushImage,\n\t\tImageRepo:    ref.Repo,\n\t\tImageTag:     ref.Tag,\n\t\tBuildContext: w,\n\t}, nil\n}\n\ntype buildRunner struct {\n\tlatest.BuildHooks\n\topts BuildEnvOpts","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/hooks/build.go#L22-L58","documentation":"NewBuildEnvOpts prepares the environment for build lifecycle hooks. It first parses the image string into a Docker reference (repo, tag) with docker.ParseReference. If the image string is not a valid container image reference, the parse error is wrapped as 'parsing image %v: %w'.","triggerScenarios":"Invoking a build hook runner (via NewBuildEnvOpts) with an image value that is empty, contains invalid characters, has an invalid tag/digest, or an unparseable registry portion — anything rejected by docker's reference parser.","commonSituations":"A custom build hook configured for an artifact whose produced image string is malformed; image names with uppercase characters or illegal characters like spaces; empty image produced by a failed/incomplete builder; tag containing invalid characters (e.g. '+', leading '-').","solutions":["Inspect the image string in the error message and correct its format (lowercase name, valid tag/digest)","Verify the builder actually produced a non-empty image name/tag before hooks run","Validate the reference locally with 'docker tag <image> <image>' to see the parser complaint","If the image comes from a previous build step, fix the upstream artifact image name in skaffold.yaml"],"exampleFix":"// before\nerr := hooks.NewBuildEnvOpts(artifact, \"My Image:v1!\", pushImage)\n// after\nerr := hooks.NewBuildEnvOpts(artifact, \"registry.example.com/my-image:v1\", pushImage)","handlingStrategy":"validation","validationCode":"func validImageRef(image string) bool {\n    _, err := docker.ParseReference(image)\n    return err == nil && image != \"\"\n}\nif !validImageRef(image) { return fmt.Errorf(\"invalid image %q\", image) }\nopts, err := hooks.NewBuildEnvOpts(a, image, push)","typeGuard":null,"tryCatchPattern":"opts, err := hooks.NewBuildEnvOpts(a, image, push)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"parsing image\") {\n        return fmt.Errorf(\"image %q is not a valid docker reference\", image)\n    }\n    return err\n}","preventionTips":["Use lowercase image names and valid tags ([a-zA-Z0-9_.-] only)","Assert the builder produced a non-empty image before hooks run","Validate references with 'docker pull --dry-run' style checks in CI"],"tags":["docker","image-reference","hooks","validation"],"backgroundTag":"invalid-image-reference","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}