{"record":{"id":"7efc373712d15cfe","repo":"theonedev/onedev","slug":"file-not-found-or-not-a-text-file-in-head-commit","errorCode":null,"errorMessage":"File not found or not a text file in head commit: ${filePath}","messagePattern":"File not found or not a text file in head commit: (.+?)","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java","lineNumber":157,"sourceCode":"            int fromLineNumber, int toLineNumber, String commentContent) {\n        if (fromLineNumber <= 0)\n            throw new NotAcceptableException(\"'fromLineNumber' must be greater than 0\");\n        if (fromLineNumber > toLineNumber)\n            throw new NotAcceptableException(\"'fromLineNumber' must be less than or equal to 'toLineNumber'\");\n\n        var project = pullRequest.getProject();\n        var pullRequestService = OneDev.getInstance(PullRequestService.class);\n        var gitService = OneDev.getInstance(GitService.class);\n        var codeCommentService = OneDev.getInstance(CodeCommentService.class);\n\n        var oldCommitId = ObjectId.fromString(pullRequest.getBaseCommitHash());\n        var newCommitId = ObjectId.fromString(pullRequest.getLatestUpdate().getHeadCommitHash());\n        var comparisonBase = pullRequestService.getComparisonBase(pullRequest, oldCommitId, newCommitId);\n\n        var newBlobIdent = new BlobIdent(newCommitId.name(), filePath, FileMode.REGULAR_FILE.getBits());\n        var lines = project.readLines(newBlobIdent, WhitespaceOption.IGNORE_TRAILING, false);\n        if (lines == null)\n            throw new NotFoundException(\"File not found or not a text file in head commit: \" + filePath);\n        if (toLineNumber > lines.size())\n            throw new NotAcceptableException(\"'toLineNumber' must not exceed number of lines in the file\");\n\n        DiffEntryFacade matchingEntry = null;\n        for (var entry : gitService.diff(project, comparisonBase, newCommitId)) {\n            if (filePath.equals(entry.getNewPath()) && entry.getChangeType() != ChangeType.DELETE) {\n                matchingEntry = entry;\n                break;\n            }\n        }\n        if (matchingEntry == null)\n            throw new NotAcceptableException(\"Cannot add code comment outside of diff: '\" + filePath + \"' is not changed\");\n\n        var changeType = matchingEntry.getChangeType();\n        if (changeType == ChangeType.RENAME && matchingEntry.getOldPath().equals(matchingEntry.getNewPath()))\n            changeType = ChangeType.MODIFY;\n        var oldDiffBlobIdent = GitUtils.getOldBlobIdent(matchingEntry, comparisonBase.name());\n        var newDiffBlobIdent = GitUtils.getNewBlobIdent(matchingEntry, newCommitId.name());","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java#L139-L175","documentation":"addCodeComment looks up filePath in the head commit as a readable text blob (project.readLines); a null result means the path does not exist there or is binary/non-text, so a line-anchored comment is impossible.","triggerScenarios":"Thrown at server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java:157 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the file path exists in the head commit of the pull request.","Only comment on text files; skip binary or deleted paths.","Re-read the changed-file list from the PR diff and use one of those paths."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}