{"record":{"id":"e2695cc82000b87f","repo":"dagger/dagger","slug":"select-latest-git-ref-nil-remote","errorCode":null,"errorMessage":"select latest git ref: nil remote","messagePattern":"select latest git ref: nil remote","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/git.go","lineNumber":100,"sourceCode":"\tmount(ctx context.Context, depth int, includeTags bool, fn func(*gitutil.GitCLI) error) error\n}\n\n// SelectLatestGitRef selects the greatest stable release tag in remote after\n// normalizing optional v prefixes, incomplete versions, and zero-padded numeric\n// components. It falls back to HEAD when no eligible release tag exists.\nfunc SelectLatestGitRef(remote *gitutil.Remote) (*gitutil.Ref, error) {\n\treturn SelectLatestGitRefWithTagPrefix(remote, \"\")\n}\n\n// SelectLatestGitRefWithTagPrefix selects the greatest normalized stable\n// release tag below tagPrefix. If no matching prefixed release exists,\n// repository-wide release tags are considered before falling back to HEAD.\nfunc SelectLatestGitRefWithTagPrefix(\n\tremote *gitutil.Remote,\n\ttagPrefix string,\n) (*gitutil.Ref, error) {\n\tif remote == nil {\n\t\treturn nil, fmt.Errorf(\"select latest git ref: nil remote\")\n\t}\n\n\ttagPrefix = strings.Trim(tagPrefix, \"/\")\n\tif tagPrefix != \"\" {\n\t\ttagPrefix += \"/\"\n\t}\n\n\tbestRef, err := selectLatestGitRelease(remote, tagPrefix)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif bestRef == \"\" && tagPrefix != \"\" {\n\t\tbestRef, err = selectLatestGitRelease(remote, \"\")\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/git.go#L82-L118","documentation":"This error is returned by SelectLatestGitRefWithTagPrefix when the provided *gitutil.Remote is nil. The library throws it because ref lookups require a live remote; a nil remote means no repository source to query.","triggerScenarios":"Calling SelectLatestGitRef / SelectLatestGitRefWithTagPrefix with a remote value that was never initialized (e.g. an upstream Remote() call returned nil and was passed through unchecked).","commonSituations":"GitRepository not yet loaded/cloned so its remote handle is unset; error path earlier returned nil remote without surfacing; test harness omitted remote setup.","solutions":["Ensure the GitRepository was initialized and its Remote() returned a non-nil value before calling this","Check for earlier errors that left the remote nil but were swallowed","Guard the call site: if remote == nil, initialize or return a clearer upstream error","Add a test covering the uninitialized-repository path"],"exampleFix":"// before\nref, err := SelectLatestGitRef(repo.remote, \"v\") // remote is nil\n// after\nif repo.remote == nil {\n    return nil, fmt.Errorf(\"repository has no remote; was it loaded?\")\n}\nref, err := SelectLatestGitRef(repo.remote, \"v\")","handlingStrategy":"validation","validationCode":"if remote == nil {\n    return nil, fmt.Errorf(\"cannot select latest ref: remote not initialized\")\n}\nref, err := SelectLatestGitRefWithTagPrefix(remote, prefix)","typeGuard":"func hasRemote(r *gitutil.Remote) bool { return r != nil }","tryCatchPattern":"ref, err := SelectLatestGitRef(repo.Remote())\nif err != nil {\n    if err.Error() == \"select latest git ref: nil remote\" {\n        return nil, fmt.Errorf(\"repository not loaded; call clone/load first\")\n    }\n    return err\n}","preventionTips":["Always check GitRepository.Remote() / upstream errors before use","Initialize the repository (load/clone) before ref operations","Surface early errors instead of passing nil remotes downstream","Add a test for the uninitialized repository path"],"tags":["git","nil-pointer","validation","remote"],"backgroundTag":"nil-remote-reference","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"}