{"record":{"id":"e26ffcea507b4f76","repo":"theonedev/onedev","slug":"error-parsing-query","errorCode":null,"errorMessage":"Error parsing query","messagePattern":"Error parsing query","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/PackResource.java","lineNumber":120,"sourceCode":"    \tif (!SecurityUtils.canWritePack(pack.getProject()))\n\t\t\tthrow new UnauthorizedException();\n    \tpackService.delete(pack);\n\t\tvar oldAuditContent = VersionedXmlDoc.fromBean(pack).toXML();\n\t\tauditService.audit(pack.getProject(), \"deleted package \\\"\" + pack.getReference(false) + \"\\\" via RESTful API\", oldAuditContent, null);\n    \treturn Response.ok().build();\n    }\n\n\t@Api(order=800, description=\"Delete all packages matching query\")\n\t@DELETE\n\tpublic Response deletePacks(\n\t\t\t@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) {\n\t\tvar subject = SecurityUtils.getSubject();\n\n\t\tPackQuery parsedQuery;\n\t\ttry {\n\t\t\tparsedQuery = PackQuery.parse(null, query, true);\n\t\t} catch (Exception e) {\n\t\t\tthrow new NotAcceptableException(\"Error parsing query\", e);\n\t\t}\n\n\t\tvar packs = packService.query(subject, null, parsedQuery, false, 0, Integer.MAX_VALUE);\n\t\tfor (var pack: packs) {\n\t\t\tif (!SecurityUtils.canWritePack(subject, pack.getProject()))\n\t\t\t\tthrow new UnauthorizedException();\n\t\t}\n\t\tpackService.delete(packs);\n\t\tfor (var pack: packs) {\n\t\t\tvar oldAuditContent = VersionedXmlDoc.fromBean(pack).toXML();\n\t\t\tauditService.audit(pack.getProject(), \"deleted package \\\"\" + pack.getReference(false) + \"\\\" via RESTful API\", oldAuditContent, null);\n\t\t}\n\t\treturn Response.ok().build();\n\t}\n\t\n}\n","sourceCodeStart":102,"sourceCodeEnd":137,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/PackResource.java#L102-L137","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Validate the query in the Packages page search box first; only then reuse it in the API call.","Check the query syntax documentation: \"Field\" is \"Value\" style with proper quoting.","URL-encode the query parameter correctly in the HTTP client.","Log/inspect the wrapped cause 'e' returned with the exception for the exact parse position.","Simplify the query (start with one criterion) and add complexity back incrementally."],"exampleFix":"// before (unquoted field value / bad syntax)\ncurl -X DELETE \"http://server/~api/packs?query=Type is Docker Image\"\n// after\ncurl -X DELETE \"http://server/~api/packs?query=%22Type%22%20is%20%22Docker%20Image%22","handlingStrategy":"validation","validationCode":"// test the query through the read API before deleting\ntry {\n    PackQuery.parse(null, query, true); // or: GET /~api/packs?query=... first\n} catch (Exception e) {\n    throw new IllegalArgumentException(\"Invalid pack query: \" + query, e);\n}","typeGuard":null,"tryCatchPattern":"try { client.deletePacks(query); } catch (NotAcceptableException e) { log.error(\"Bad query '{}': {}\", query, e.getCause()); }","preventionTips":["Validate queries in the Packages page UI first","URL-encode quotes and spaces in the query parameter","Keep a small library of tested query strings","Inspect the wrapped cause for the parse error position"],"tags":["rest","query-syntax","validation","onedev"],"backgroundTag":"invalid-query-parameter","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"}