{"record":{"id":"d7bbc97baa4da6da","repo":"pockethub/PocketHub","slug":"request-for-git-reference-was-unsuccessful","errorCode":null,"errorMessage":"Request for Git Reference was unsuccessful","messagePattern":"Request for Git Reference was unsuccessful","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/com/github/pockethub/android/core/code/RefreshTreeTask.java","lineNumber":83,"sourceCode":"\n    private boolean isValidRef(GitReference ref) {\n        return ref != null && ref.object() != null\n                && !TextUtils.isEmpty(ref.object().sha());\n    }\n\n    private Single<GitReference> getValidRef(GitService service, GitReference ref, String branch) {\n        if (!isValidRef(ref)) {\n            return service.getGitReference(repo.owner().login(), repo.name(), branch)\n                    .map(response -> {\n                        if (response.isSuccessful()) {\n                            GitReference fetchedRef = response.body();\n                            if (isValidRef(fetchedRef)) {\n                                return fetchedRef;\n                            } else {\n                                throw new IOException(\"Reference does not have associated commit SHA-1\");\n                            }\n                        } else {\n                            throw new IOException(\"Request for Git Reference was unsuccessful\");\n                        }\n                    });\n        }\n\n        return Single.just(ref);\n    }\n\n    private Single<String> getBranch(GitReference ref) {\n        String branch = RefUtils.getPath(ref);\n        if (branch == null) {\n            branch = repo.defaultBranch();\n            if (TextUtils.isEmpty(branch)) {\n                return ServiceGenerator\n                        .createService(context, RepositoryService.class)\n                        .getRepository(repo.owner().login(), repo.name())\n                        .map(response -> response.body().defaultBranch());\n            }\n        }","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/pockethub/PocketHub/blob/8228cb8f7197a7c2227e67ee48a2c8dc843fb553/app/src/main/java/com/github/pockethub/android/core/code/RefreshTreeTask.java#L65-L101","documentation":"getValidRef() throws this IOException when the HTTP request for the GitReference completes but is not successful (non-2xx). The wrapped Single signals an error to the subscriber of refresh(). It distinguishes API-level failure from a valid-but-invalid ref payload.","triggerScenarios":"The GET refs/{ref} call returns a non-successful HTTP code — 404 (branch/tag doesn't exist), 401/403 (auth problems), 422, or 5xx from GitHub.","commonSituations":"Requesting a branch that was deleted or never existed; expired/insufficient auth token; private repo accessed without permission; transient GitHub 5xx.","solutions":["Check the ref name spelling and that the branch/tag exists ('git ls-remote origin').","Verify authentication/token scopes for the repository (401/403).","Add retry logic (RxJava retryWhen with backoff) for transient 5xx/network errors.","Handle the IOException in the subscribe error consumer and surface a user-facing message."],"exampleFix":"// before\nstore.refreshGist(...)\n    .subscribe(this::onLoaded);\n// after\nstore.refreshGist(...)\n    .retryWhen(errors -> errors.flatMap(e -> Observable.timer(1, TimeUnit.SECONDS)))\n    .subscribe(this::onLoaded, err -> showError(err.getMessage()));","handlingStrategy":"retry","validationCode":"// check ref exists and token valid:\n// git ls-remote https://github.com/<owner>/<repo>.git refs/heads/<ref>","typeGuard":null,"tryCatchPattern":"source.subscribe(\n    { ref -> /* handle */ },\n    { e -> showError(if (e is IOException) e.message else \"unknown\") }\n)","preventionTips":["Confirm branch/tag exists before requesting","Keep auth tokens fresh with correct scopes","Retry 5xx/429 with exponential backoff","Surface HTTP codes to the user for diagnosability"],"tags":["github-api","http-error","network","ref-not-found"],"backgroundTag":"http-error-response","analyzedSha":"8228cb8f7197a7c2227e67ee48a2c8dc843fb553","analyzedAt":"2026-09-11T10:16:17.606Z","contentChangedAt":"2026-09-11T10:16:17.606Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}