{"record":{"id":"ae436e9ed80b28f6","repo":"theonedev/onedev","slug":"build-not-found-referencestring","errorCode":null,"errorMessage":"Build not found: ${referenceString}","messagePattern":"Build not found: (.+?)","errorType":"exception","errorClass":"javax.ws.rs.NotFoundException","httpStatus":404,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/ai/TodResource.java","lineNumber":1807,"sourceCode":"            } else {\n                return Response.status(NOT_ACCEPTABLE).entity(Joiner.on(\"\\n\").join(validationErrors) + schemaNotice).build();\n            }\n        } catch (Exception e) {\n            return Response.status(NOT_ACCEPTABLE).entity(Throwables.getStackTraceAsString(e) + schemaNotice).build();\n\t\t} finally {\n\t\t\tProject.pop();\n\t\t}\n    }\n\n    private Build getBuild(Project currentProject, String referenceString) {\n        var buildReference = BuildReference.of(referenceString, currentProject);\n        var build = buildService.find(buildReference.getProject(), buildReference.getNumber());\n        if (build != null) {\n            if (!SecurityUtils.canAccessProject(build.getProject()))\n                throw new UnauthorizedException(\"No permission to access build: \" + referenceString);\n            return build;\n        } else {\n            throw new NotFoundException(\"Build not found: \" + referenceString);\n        }\n    }\n    \n    private void normalizePullRequestData(Map<String, Serializable> data) {\n        for (var entry : data.entrySet()) {\n            if (entry.getValue() instanceof String)\n                entry.setValue(trimToNull((String) entry.getValue()));\n        }\n    }    \n\n    private static class ProjectContext {\n        \n        Project project;\n\n        Project currentProject;\n    }\n\n    private static class VersionInfo {","sourceCodeStart":1789,"sourceCodeEnd":1825,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/ai/TodResource.java#L1789-L1825","documentation":"getBuild throws NotFoundException when BuildReference.of parses the reference and buildService.find returns no build for the referenced project/number. The message includes the original reference string to aid debugging.","triggerScenarios":"Passing a build reference string (e.g. '#999' or 'project/#999') where no build with that number exists in the resolved project, or the project part of the reference names a non-existent/inaccessible project yielding no match.","commonSituations":"Typos in build numbers; referencing builds from another project without the project prefix; referencing builds that were cleaned up/purged; AI agents hallucinating build numbers.","solutions":["Verify the build number exists in the target project (list recent builds first).","If the build lives in another project, include the project path in the reference, e.g. 'my-project/#42'.","Check the project path spelling in the reference."],"exampleFix":"// before\nBuild b = getBuild(currentProject, \"#999\"); // no such build\n// after\nBuild b = getBuild(currentProject, \"#42\"); // existing build number","handlingStrategy":"validation","validationCode":"// resolve and check the build exists before use\nconst build = await findBuild(projectPath, number);\nif (!build) throw new Error(`Build ${projectPath}/#${number} does not exist`);","typeGuard":"function isValidBuildRef(ref) { return /^([\\w.-]+\\/)?#\\d+$/.test(ref); }","tryCatchPattern":"try { return getBuild(ref); } catch (e) { if (e.status === 404 && /Build not found/.test(e.message)) { const candidates = await listRecentBuilds(refProject); return promptUserToPick(candidates); } throw e; }","preventionTips":["Fetch builds via list APIs instead of hardcoding numbers","Always qualify references with the project path for cross-project lookups","Remember purged builds no longer resolve"],"tags":["not-found","rest-api","build"],"backgroundTag":"record-not-found","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}