{"record":{"id":"696f67eee22c69f1","repo":"dagger/dagger","slug":"cannot-export-a-synthetic-workspace","errorCode":null,"errorMessage":"cannot export a synthetic workspace","messagePattern":"cannot export a synthetic workspace","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/workspace.go","lineNumber":446,"sourceCode":"\t}\n}\n\nfunc (ws *Workspace) ExportHostPath() (string, error) {\n\tif ws == nil {\n\t\treturn \"\", fmt.Errorf(\"workspace is required\")\n\t}\n\tswitch src := ws.BaseSource().(type) {\n\tcase *WorkspaceSourceClientLocal:\n\t\tif src.HostPath == \"\" {\n\t\t\treturn \"\", fmt.Errorf(\"workspace export requires a local Git workspace\")\n\t\t}\n\t\treturn src.HostPath, nil\n\tcase *WorkspaceSourceRootlessLocal:\n\t\treturn \"\", fmt.Errorf(\"workspace export requires a local Git workspace\")\n\tcase *WorkspaceSourceGitRef:\n\t\treturn \"\", fmt.Errorf(\"cannot export a remote Git workspace\")\n\tcase *WorkspaceSourceDirectory:\n\t\treturn \"\", fmt.Errorf(\"cannot export a synthetic workspace\")\n\tcase nil:\n\t\treturn \"\", fmt.Errorf(\"workspace export requires a local Git workspace\")\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"cannot export workspace source %T\", src)\n\t}\n}\n\nfunc (ws *Workspace) IsValueWorkspace() bool {\n\tif ws == nil || ws.ClientID != \"\" {\n\t\treturn false\n\t}\n\tswitch ws.Source().(type) {\n\tcase *WorkspaceSourceDirectory, *WorkspaceSourceGitRef, *WorkspaceSourceOverlay:\n\t\treturn true\n\tdefault:\n\t\treturn false\n\t}\n}","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/workspace.go#L428-L464","documentation":"The workspace's base source is *WorkspaceSourceDirectory — a synthetic, in-engine directory with no git or host backing. There is no host path to expose for a purely synthetic workspace, so ExportHostPath refuses.","triggerScenarios":"Calling ExportHostPath on a workspace built from a Directory (e.g. container.directory(...) or a constructed directory tree) rather than a client-local git checkout.","commonSituations":"Composing workspaces from generated directories in a pipeline, then trying to pass a host path to a local tool or test harness; forgetting that only client-local git workspaces have host paths.","solutions":["Export the directory contents via Directory.Export to a host destination instead of using ExportHostPath","Construct the workspace from a client-local git directory if a host path is genuinely required","Guard the call by checking the workspace source type first"],"exampleFix":"// before\npath, err := ws.ExportHostPath()\n// after\ndir := ws.Directory()\nif err := dir.Export(ctx, \"./out\"); err != nil {\n  return err\n}\npath := \"./out\"","handlingStrategy":"fallback","validationCode":"if _, ok := ws.BaseSource().(*core.WorkspaceSourceDirectory); ok {\n  return ws.Directory().Export(ctx, dest) // synthetic: export contents, not a path\n}","typeGuard":"func isSynthetic(ws *core.Workspace) bool {\n  _, ok := ws.BaseSource().(*core.WorkspaceSourceDirectory)\n  return ok\n}","tryCatchPattern":"path, err := ws.ExportHostPath()\nif err != nil && strings.Contains(err.Error(), \"synthetic workspace\") {\n  return ws.Directory().Export(ctx, dest)\n}","preventionTips":["Use Directory.Export for constructed/synthetic workspaces","Only rely on host paths for client-local git workspaces","Document in pipelines which workspace kinds require host paths"],"tags":["workspace","export","directory"],"backgroundTag":"workspace-export-not-local","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}