theonedev/onedev · error · io.onedev.server.exception.NotAcceptableException

Job name is required

Error message

Job name is required

What it means

The run-job endpoint validates that the request body contains a 'jobName' entry; trimToNull((String)data.get("jobName")) returning null triggers NotAcceptableException('Job name is required') (HTTP 406-style validation failure). The user was authenticated but the payload is incomplete.

Source

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

    }

    @SuppressWarnings("unchecked")
    @Path("/run-job")
    @POST
    public Map<String, Object> runJob(
                @QueryParam("currentProject") @NotNull String currentProjectPath, 
                @NotNull @Valid Map<String, Serializable> data) {
        var subject = SecurityUtils.getSubject();
        var user = SecurityUtils.getUser(subject);

        if (user == null)
            throw new UnauthenticatedException();

        var project = getProject(currentProjectPath);

        var jobName = trimToNull((String)data.get("jobName"));
        if (jobName == null)
            throw new NotAcceptableException("Job name is required");

        if (!SecurityUtils.canRunJob(subject, project, jobName))		
            throw new UnauthorizedException();

        String refName;
        var branch = trimToNull((String)data.get("branch"));
        var tag = trimToNull((String)data.get("tag"));
        var commitHash = trimToNull((String)data.get("commitHash"));
        if (commitHash != null) {
            refName = trimToNull((String)data.get("refName"));
            if (refName == null) {
                throw new NotAcceptableException("Ref name is required when commit hash is specified");
            }
        } else if (branch != null) {            
            refName = GitUtils.branch2ref(branch);
        } else if (tag != null) {
            refName = GitUtils.tag2ref(tag);
        } else {

View on GitHub (pinned to d44925c47c)

Solutions

  1. Add a non-empty 'jobName' string field to the request body.
  2. Fix the client key name to exactly 'jobName' (case-sensitive).
  3. Trim/validate the value before sending so it is not blank.
  4. In client code, reject requests where !(data.jobName is a non-empty string) before calling the endpoint.

Example fix

// before
var data = Map.of("branch", "main"); // Job name is required
// after
var data = Map.of("jobName", "build-and-test", "branch", "main");
Defensive patterns

Strategy: validation

Validate before calling

String jobName = (String) data.get("jobName");
if (jobName == null || jobName.trim().isEmpty()) {
    throw new NotAcceptableException("'jobName' must be a non-empty string");
}

Type guard

function hasJobName(data) {
  return data != null && typeof data.jobName === 'string' && data.jobName.trim().length > 0;
}

Try / catch

try {
    runJob(projectPath, data);
} catch (NotAcceptableException e) {
    if (e.getMessage().contains("Job name is required")) {
        log.error("Payload missing jobName; keys sent: {}", data.keySet());
    }
}

Prevention

When it happens

Trigger: POSTing to the run-job endpoint with a data map that omits 'jobName', sets it to an empty string, or sets a non-string value (e.g. a number or nested object) that the cast treats as unusable.

Common situations: AI tool schema drift: client sends 'job' instead of 'jobName'; whitespace-only value after trim; JSON produced programmatically with a null field omitted entirely.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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