theonedev/onedev · error · RuntimeException

Malformed query

Error message

Malformed query

What it means

PackQuery.parse lexes and parses the pack query string with an ANTLR lexer/parser. Both are configured with a BaseErrorListener that converts any ANTLR syntax error into a RuntimeException('Malformed query', e), so an unparseable query text surfaces as this error.

Source

Thrown at server-core/src/main/java/io/onedev/server/search/entity/pack/PackQuery.java:81

	public PackQuery(@Nullable Criteria<Pack> criteria) {
		super(criteria, new ArrayList<>());
	}
	
	public PackQuery() {
		super(null, new ArrayList<>());
	}
	
	public static PackQuery parse(@Nullable Project project, @Nullable String queryString, boolean withCurrentUserCriteria) {
		if (queryString != null) {
			CharStream is = CharStreams.fromString(queryString); 
			PackQueryLexer lexer = new PackQueryLexer(is);
			lexer.removeErrorListeners();
			lexer.addErrorListener(new BaseErrorListener() {

				@Override
				public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
						int charPositionInLine, String msg, RecognitionException e) {
					throw new RuntimeException("Malformed query", e);
				}
				
			});
			CommonTokenStream tokens = new CommonTokenStream(lexer);
			PackQueryParser parser = new PackQueryParser(tokens);
			parser.removeErrorListeners();
			parser.setErrorHandler(new BailErrorStrategy());
			QueryContext queryContext = parser.query();
			CriteriaContext criteriaContext = queryContext.criteria();
			Criteria<Pack> packCriteria;
			if (criteriaContext != null) {
				packCriteria = new PackQueryBaseVisitor<Criteria<Pack>>() {

					@Override
					public Criteria<Pack> visitFuzzyCriteria(FuzzyCriteriaContext ctx) {
						return new FuzzyCriteria(getValue(ctx.getText()));
					}
					

View on GitHub (pinned to d44925c47c)

Solutions

  1. Fix the query syntax per pack query grammar (quote values, correct operators, balanced parens)
  2. Simplify the query and re-add clauses until the offending part is found
  3. Validate the query in the UI query editor which reports parse problems before saving
  4. Catch the RuntimeException and surface e's ANTLR message to locate the offending token

Example fix

// before
PackQuery.parse(project, "published by "me"") // broken quoting
// after
PackQuery.parse(project, "\"published by\" \"me\"") // correctly quoted per grammar
Defensive patterns

Strategy: try-catch

Validate before calling

function validatePackQuery(q) { const tokens = q.match(/"[^"]*"|\S+/g); if (!tokens) throw new Error('empty query'); const open = (q.match(/\(/g)||[]).length, close = (q.match(/\)/g)||[]).length; if (open !== close) throw new Error('unbalanced parens'); }

Type guard

null

Try / catch

try { query = PackQuery.parse(project, q); } catch (RuntimeException e) { log.warn("Malformed pack query: {}", q, e); throw new UserInputError("Invalid pack query syntax"); }

Prevention

When it happens

Trigger: Calling PackQuery.parse with a query string that violates the pack query grammar — unbalanced quotes/parentheses, unknown tokens, invalid operator placement, or trailing garbage.

Common situations: Hand-written query strings in saved queries or API calls; queries built by string concatenation without escaping; users typing free-text search into a structured query field; grammar changes between OneDev versions making old queries invalid.

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/7eb3081e6086c476. Report an issue: GitHub.