{"record":{"id":"bf63088a8ed75449","repo":"cli/cli","slug":"a-value-is-required","errorCode":null,"errorMessage":"a value is required","messagePattern":"a value is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/ghinstance/host.go","lineNumber":38,"sourceCode":"// Default returns the host name of the default GitHub instance.\nfunc Default() string {\n\treturn defaultHostname\n}\n\n// TenantName extracts the tenant name from tenancy host name and\n// reports whether it found the tenant name.\nfunc TenantName(h string) (string, bool) {\n\tnormalizedHostName := ghauth.NormalizeHostname(h)\n\treturn strings.CutSuffix(normalizedHostName, \".\"+tenancyHost)\n}\n\nfunc isGarage(h string) bool {\n\treturn strings.EqualFold(h, \"garage.github.com\")\n}\n\nfunc HostnameValidator(hostname string) error {\n\tif len(strings.TrimSpace(hostname)) < 1 {\n\t\treturn errors.New(\"a value is required\")\n\t}\n\tif strings.ContainsRune(hostname, '/') || strings.ContainsRune(hostname, ':') {\n\t\treturn errors.New(\"invalid hostname\")\n\t}\n\treturn nil\n}\n\nfunc GraphQLEndpoint(hostname string) string {\n\tif isGarage(hostname) {\n\t\treturn fmt.Sprintf(\"https://%s/api/graphql\", hostname)\n\t}\n\tif ghauth.IsEnterprise(hostname) {\n\t\treturn fmt.Sprintf(\"https://%s/api/graphql\", hostname)\n\t}\n\tif strings.EqualFold(hostname, localhost) {\n\t\treturn fmt.Sprintf(\"http://api.%s/graphql\", hostname)\n\t}\n\treturn fmt.Sprintf(\"https://api.%s/graphql\", hostname)","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/cli/cli/blob/0eeec0b92edbe70199f9768522f831d3534f41ad/internal/ghinstance/host.go#L20-L56","documentation":"Returned (as *NotFoundError) when the PR finder has neither a PR number/URL nor a usable (base repo + branch name) pair to search with. It is a typed NotFoundError, so callers can distinguish 'not found' from hard failures. It usually means the command cannot even formulate a query.","triggerScenarios":"Running `gh pr view/status/checkout` style commands with no argument where: the current directory is not a git repo (no branch name), no base repo can be resolved, and no selector was given. Also when branchName is empty (detached HEAD).","commonSituations":"Running gh outside a git repository; detached HEAD in CI; scripts that assume a branch context that does not exist.","solutions":["Pass an explicit selector: `gh pr view 123`, `gh pr view https://github.com/o/r/pull/123`, or `--repo owner/repo`.","Ensure you are inside the repository checkout and on a branch: `git rev-parse --abbrev-ref HEAD`.","Detect this case in code with errors.As(err, &NotFoundError{}) instead of string matching."],"exampleFix":"# before\ngh pr view  # in a non-repo dir -> no pull requests found\n\n# after\ngh pr view --repo acme/widgets 123","handlingStrategy":"type-guard","validationCode":"if selector == \"\" && branchName == \"\" {\n    return errors.New(\"no PR selector and no branch context: pass a number, URL, or --repo\")\n}","typeGuard":"func isNotFound(err error) bool {\n    var nf *shared.NotFoundError\n    return errors.As(err, &nf)\n}","tryCatchPattern":"pr, repo, err := finder.Find(opts)\nif err != nil {\n    var nf *shared.NotFoundError\n    if errors.As(err, &nf) {\n        // not-found: create the PR or prompt, do not report a hard error\n    }\n    return err\n}","preventionTips":["Always pass an explicit selector in scripts.","Ensure the working directory is a git checkout on a branch.","Branch on the typed NotFoundError rather than matching message strings."],"tags":["not-found","git-context","finder","cli"],"backgroundTag":null,"analyzedSha":"0eeec0b92edbe70199f9768522f831d3534f41ad","analyzedAt":"2026-08-15T12:31:05.478Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}