{"record":{"id":"6f5c75df9f61132a","repo":"GoogleContainerTools/skaffold","slug":"determining-build-workspace-directory-for-image-v","errorCode":null,"errorMessage":"determining build workspace directory for image %v: %w","messagePattern":"determining build workspace directory for image (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/hooks/build.go","lineNumber":45,"sourceCode":"\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\n}\n\nfunc (r buildRunner) RunPreHooks(ctx context.Context, out io.Writer) error {\n\treturn r.run(ctx, out, r.PreHooks, phases.PreBuild)\n}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/hooks/build.go#L27-L63","documentation":"NewBuildEnvOpts resolves the artifact's build workspace to an absolute path with filepath.Abs before constructing BuildEnvOpts. If obtaining the absolute path fails (rare OS-level path resolution failure), the error is wrapped as 'determining build workspace directory for image %v: %w'.","triggerScenarios":"Calling NewBuildEnvOpts with a latest.Artifact whose Workspace is set and filepath.Abs returns an error — typically only when the current working directory cannot be resolved (deleted cwd, permission issues) or the path is unresolvable on the OS.","commonSituations":"Running skaffold from a directory that was deleted or replaced while the process ran; a workspace path referencing a mount that disappeared; exotic path-resolution failures on constrained container environments.","solutions":["Re-run skaffold from an existing, accessible working directory","Check that the artifact's workspace path in skaffold.yaml points to an existing directory","Recreate/re-mount any missing mount or deleted directory","Update to a newer skaffold if the cwd was valid — filepath.Abs rarely fails otherwise"],"exampleFix":"// before: cwd deleted mid-run\nos.Chdir(\"/tmp/build\") // /tmp/build removed by another process\nopts, err := hooks.NewBuildEnvOpts(a, image, push) // fails\n// after: ensure cwd and workspace exist\nif _, err := os.Stat(a.Workspace); err != nil { return err }\nopts, err := hooks.NewBuildEnvOpts(a, image, push)","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(a.Workspace); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"workspace %q unavailable\", a.Workspace)\n}\nopts, err := hooks.NewBuildEnvOpts(a, image, push)","typeGuard":null,"tryCatchPattern":"opts, err := hooks.NewBuildEnvOpts(a, image, push)\nif err != nil {\n    if strings.Contains(err.Error(), \"determining build workspace\") {\n        return fmt.Errorf(\"cannot resolve workspace %q; check cwd/mounts\", a.Workspace)\n    }\n    return err\n}","preventionTips":["Never delete/replace the cwd while skaffold runs","Use absolute, existing workspace paths in skaffold.yaml","Run skaffold in a stable container/workdir for CI"],"tags":["filesystem","workspace","hooks","path"],"backgroundTag":"workspace-path-resolution-failed","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"}