{"record":{"id":"97bf628a340fc9d4","repo":"dagger/dagger","slug":"remote-workspace-q-parsing-git-ref-w","errorCode":null,"errorMessage":"remote workspace %q: parsing git ref: %w","messagePattern":"remote workspace %q: parsing git ref: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/server/session_workspaces.go","lineNumber":363,"sourceCode":"\tif subdir == \"\" {\n\t\treturn \".\", nil\n\t}\n\tsubdir = filepath.Clean(subdir)\n\tsubdir = strings.TrimPrefix(subdir, string(filepath.Separator))\n\tif subdir == \"\" || subdir == \".\" {\n\t\treturn \".\", nil\n\t}\n\tif !filepath.IsLocal(subdir) {\n\t\treturn \"\", fmt.Errorf(\"path points outside repository: %q\", subdir)\n\t}\n\treturn subdir, nil\n}\n\n// loadWorkspaceFromRemote clones a git repo and detects/loads the workspace from it.\nfunc (srv *Server) loadWorkspaceFromRemote(ctx context.Context, client *daggerClient, remoteRef string) error {\n\tparsedRef, err := parseWorkspaceRemoteRef(ctx, remoteRef)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"remote workspace %q: parsing git ref: %w\", remoteRef, err)\n\t}\n\n\ttree, gitRef, err := srv.cloneGitTree(ctx, client.dag, parsedRef.cloneRef, parsedRef.version)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"remote workspace %q: %w\", remoteRef, err)\n\t}\n\n\tresolveLocalRef := func(ws *workspace.Workspace, relPath string) string {\n\t\tsubPath := filepath.Join(ws.Root, relPath)\n\t\treturn core.GitRefString(parsedRef.cloneRef, subPath, parsedRef.version)\n\t}\n\n\treturn srv.detectAndLoadWorkspaceWithRootfs(ctx, client,\n\t\t&core.DirectoryStatFS{Dir: tree},\n\t\tfunc(ctx context.Context, path string) ([]byte, error) {\n\t\t\treturn core.DirectoryReadFile(ctx, tree, path)\n\t\t},\n\t\tparsedRef.workspaceSubdir,","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/engine/server/session_workspaces.go#L345-L381","documentation":"loadWorkspaceFromRemote wraps any error from parseWorkspaceRemoteRef with this prefix, indicating the remote workspace ref could not be parsed as a git URL/ref (bad URL scheme, invalid fragment, or invalid subdir).","triggerScenarios":"loadWorkspaceFromDeclaredRef falls back to the remote path and passes a ref that parseWorkspaceRemoteRef cannot parse — malformed git URL, unsupported scheme, or invalid #fragment subdir.","commonSituations":"Ref missing a valid git remote part; fragment subdir violating normalizeWorkspaceRemoteSubdir rules; user passing a plain directory name that isn't a git URL at all.","solutions":["Validate the ref is a full git URL (git ls-remote or url.Parse) before declaring it","Fix the #fragment syntax: #<ref> and #<ref>:<subdir> as supported by the parser","Check the wrapped cause for the subdir normalization error and correct the subdir","If the target is local, ensure the local dir exists so the remote branch isn't attempted"],"exampleFix":"// before\n// workspace: github.com/me/proj#main:/bad/../sub (unparseable)\n// after\n// workspace: https://github.com/me/proj.git#main:sub","handlingStrategy":"validation","validationCode":"u, err := url.Parse(ref)\nif err != nil || (u.Scheme == \"\" && !strings.HasPrefix(ref, \"git@\")) {\n    return fmt.Errorf(\"ref %q is not a parsable git URL\", ref)\n}","typeGuard":null,"tryCatchPattern":"if err := ensureWorkspaceLoaded(ctx, client, mode, ref); err != nil {\n    if strings.Contains(err.Error(), \"parsing git ref\") {\n        return fmt.Errorf(\"workspace ref %s is not a valid git ref; use https://host/repo.git[#ref[:subdir]]\", ref)\n    }\n    return err\n}","preventionTips":["Use fully qualified git URLs (https://host/repo.git) in workspace declarations","Follow the documented fragment syntax for ref/subdir","Test ref parsing locally (url.Parse + subdir sanitization) before deploying config"],"tags":["workspace","git","parsing"],"backgroundTag":"git-ref-parse-failed","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"}