theonedev/onedev · error · javax.ws.rs.NotFoundException

Build not found: ${referenceString}

Error message

Build not found: ${referenceString}

What it means

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.

Source

Thrown at server-core/src/main/java/io/onedev/server/ai/TodResource.java:1807

            } else {
                return Response.status(NOT_ACCEPTABLE).entity(Joiner.on("\n").join(validationErrors) + schemaNotice).build();
            }
        } catch (Exception e) {
            return Response.status(NOT_ACCEPTABLE).entity(Throwables.getStackTraceAsString(e) + schemaNotice).build();
		} finally {
			Project.pop();
		}
    }

    private Build getBuild(Project currentProject, String referenceString) {
        var buildReference = BuildReference.of(referenceString, currentProject);
        var build = buildService.find(buildReference.getProject(), buildReference.getNumber());
        if (build != null) {
            if (!SecurityUtils.canAccessProject(build.getProject()))
                throw new UnauthorizedException("No permission to access build: " + referenceString);
            return build;
        } else {
            throw new NotFoundException("Build not found: " + referenceString);
        }
    }
    
    private void normalizePullRequestData(Map<String, Serializable> data) {
        for (var entry : data.entrySet()) {
            if (entry.getValue() instanceof String)
                entry.setValue(trimToNull((String) entry.getValue()));
        }
    }    

    private static class ProjectContext {
        
        Project project;

        Project currentProject;
    }

    private static class VersionInfo {

View on GitHub (pinned to d44925c47c)

Solutions

  1. Verify the build number exists in the target project (list recent builds first).
  2. If the build lives in another project, include the project path in the reference, e.g. 'my-project/#42'.
  3. Check the project path spelling in the reference.

Example fix

// before
Build b = getBuild(currentProject, "#999"); // no such build
// after
Build b = getBuild(currentProject, "#42"); // existing build number
Defensive patterns

Strategy: validation

Validate before calling

// resolve and check the build exists before use
const build = await findBuild(projectPath, number);
if (!build) throw new Error(`Build ${projectPath}/#${number} does not exist`);

Type guard

function isValidBuildRef(ref) { return /^([\w.-]+\/)?#\d+$/.test(ref); }

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/ae436e9ed80b28f6. Report an issue: GitHub.