theonedev/onedev · error · NotFoundException
File not found or not a text file in head commit: ${filePath
Error message
File not found or not a text file in head commit: ${filePath} What it means
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.
Source
Thrown at server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java:157
int fromLineNumber, int toLineNumber, String commentContent) {
if (fromLineNumber <= 0)
throw new NotAcceptableException("'fromLineNumber' must be greater than 0");
if (fromLineNumber > toLineNumber)
throw new NotAcceptableException("'fromLineNumber' must be less than or equal to 'toLineNumber'");
var project = pullRequest.getProject();
var pullRequestService = OneDev.getInstance(PullRequestService.class);
var gitService = OneDev.getInstance(GitService.class);
var codeCommentService = OneDev.getInstance(CodeCommentService.class);
var oldCommitId = ObjectId.fromString(pullRequest.getBaseCommitHash());
var newCommitId = ObjectId.fromString(pullRequest.getLatestUpdate().getHeadCommitHash());
var comparisonBase = pullRequestService.getComparisonBase(pullRequest, oldCommitId, newCommitId);
var newBlobIdent = new BlobIdent(newCommitId.name(), filePath, FileMode.REGULAR_FILE.getBits());
var lines = project.readLines(newBlobIdent, WhitespaceOption.IGNORE_TRAILING, false);
if (lines == null)
throw new NotFoundException("File not found or not a text file in head commit: " + filePath);
if (toLineNumber > lines.size())
throw new NotAcceptableException("'toLineNumber' must not exceed number of lines in the file");
DiffEntryFacade matchingEntry = null;
for (var entry : gitService.diff(project, comparisonBase, newCommitId)) {
if (filePath.equals(entry.getNewPath()) && entry.getChangeType() != ChangeType.DELETE) {
matchingEntry = entry;
break;
}
}
if (matchingEntry == null)
throw new NotAcceptableException("Cannot add code comment outside of diff: '" + filePath + "' is not changed");
var changeType = matchingEntry.getChangeType();
if (changeType == ChangeType.RENAME && matchingEntry.getOldPath().equals(matchingEntry.getNewPath()))
changeType = ChangeType.MODIFY;
var oldDiffBlobIdent = GitUtils.getOldBlobIdent(matchingEntry, comparisonBase.name());
var newDiffBlobIdent = GitUtils.getNewBlobIdent(matchingEntry, newCommitId.name());View on GitHub (pinned to d44925c47c)
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at server-core/src/main/java/io/onedev/server/ai/PullRequestHelper.java:157 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/7efc373712d15cfe.
Report an issue: GitHub.