theonedev/onedev · error · NotAcceptableException

Error parsing query

Error message

Error parsing query

What it means

deletePacks takes a query string selecting the packs to delete; the string is parsed with PackQuery.parse before any deletion. If parsing fails (bad syntax, unknown criteria/value), the endpoint throws NotAcceptableException('Error parsing query') wrapping the underlying parse exception.

Source

Thrown at server-core/src/main/java/io/onedev/server/rest/resource/PackResource.java:120

    	if (!SecurityUtils.canWritePack(pack.getProject()))
			throw new UnauthorizedException();
    	packService.delete(pack);
		var oldAuditContent = VersionedXmlDoc.fromBean(pack).toXML();
		auditService.audit(pack.getProject(), "deleted package \"" + pack.getReference(false) + "\" via RESTful API", oldAuditContent, null);
    	return Response.ok().build();
    }

	@Api(order=800, description="Delete all packages matching query")
	@DELETE
	public Response deletePacks(
			@QueryParam("query") @Api(description="Syntax of this query is the same as in <a href='/~packages'>packages page</a>", example="\"Type\" is \"Container Image\"") String query) {
		var subject = SecurityUtils.getSubject();

		PackQuery parsedQuery;
		try {
			parsedQuery = PackQuery.parse(null, query, true);
		} catch (Exception e) {
			throw new NotAcceptableException("Error parsing query", e);
		}

		var packs = packService.query(subject, null, parsedQuery, false, 0, Integer.MAX_VALUE);
		for (var pack: packs) {
			if (!SecurityUtils.canWritePack(subject, pack.getProject()))
				throw new UnauthorizedException();
		}
		packService.delete(packs);
		for (var pack: packs) {
			var oldAuditContent = VersionedXmlDoc.fromBean(pack).toXML();
			auditService.audit(pack.getProject(), "deleted package \"" + pack.getReference(false) + "\" via RESTful API", oldAuditContent, null);
		}
		return Response.ok().build();
	}
	
}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Validate the query in the Packages page search box first; only then reuse it in the API call.
  2. Check the query syntax documentation: "Field" is "Value" style with proper quoting.
  3. URL-encode the query parameter correctly in the HTTP client.
  4. Log/inspect the wrapped cause 'e' returned with the exception for the exact parse position.
  5. Simplify the query (start with one criterion) and add complexity back incrementally.

Example fix

// before (unquoted field value / bad syntax)
curl -X DELETE "http://server/~api/packs?query=Type is Docker Image"
// after
curl -X DELETE "http://server/~api/packs?query=%22Type%22%20is%20%22Docker%20Image%22
Defensive patterns

Strategy: validation

Validate before calling

// test the query through the read API before deleting
try {
    PackQuery.parse(null, query, true); // or: GET /~api/packs?query=... first
} catch (Exception e) {
    throw new IllegalArgumentException("Invalid pack query: " + query, e);
}

Try / catch

try { client.deletePacks(query); } catch (NotAcceptableException e) { log.error("Bad query '{}': {}", query, e.getCause()); }

Prevention

When it happens

Trigger: DELETE /~api/packs with a 'query' parameter that violates the packages query syntax, e.g. unmatched quotes, unknown field name, wrong operator, or invalid value type.

Common situations: Query copied from the packages UI but URL-encoded incorrectly; using fields not valid in this context; shell mangling of quotes; version drift where a criterion was renamed.

Understand the failure class

Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.

Related errors


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