theonedev/onedev · error · ExplicitException

Unexpected operator: " + ctx.operator.getText()

Error message

Unexpected operator: " + ctx.operator.getText()

What it means

Thrown by JobMatch's visitOperatorValueCriteria when a field value criteria uses an operator the grammar accepted but the visitor does not handle (only OnBranch is supported for value-form criteria in that branch of the visitor). Thrown as ExplicitException listing the unexpected operator text.

Source

Thrown at server-core/src/main/java/io/onedev/server/job/match/JobMatch.java:102

					if (fieldName.equals(Build.NAME_PROJECT))
						criterias.add(new ProjectCriteria(fieldValue, operator));
					else
						criterias.add(new JobCriteria(fieldValue, operator));
				}
				return operator == IsNot? Criteria.andCriterias(criterias): Criteria.orCriterias(criterias);
			}
			
			@Override
			public Criteria<io.onedev.server.job.match.JobMatchContext> visitOperatorValueCriteria(JobMatchParser.OperatorValueCriteriaContext ctx) {
				var criterias = new ArrayList<Criteria<io.onedev.server.job.match.JobMatchContext>>();
				for (var quoted: ctx.criteriaValue.Quoted()) {
					String fieldValue = getValue(quoted.getText());
					switch (ctx.operator.getType()) {
						case OnBranch:
							criterias.add(new OnBranchCriteria(fieldValue));
							break;
						default:
							throw new ExplicitException("Unexpected operator: " + ctx.operator.getText());
					}
				}
				return Criteria.orCriterias(criterias);
			}
			
			@Override
			public Criteria<io.onedev.server.job.match.JobMatchContext> visitOrCriteria(JobMatchParser.OrCriteriaContext ctx) {
				List<Criteria<io.onedev.server.job.match.JobMatchContext>> childCriterias = new ArrayList<>();
				for (JobMatchParser.CriteriaContext childCtx: ctx.criteria())
					childCriterias.add(visit(childCtx));
				return new OrCriteria<>(childCriterias);
			}

			@Override
			public Criteria<io.onedev.server.job.match.JobMatchContext> visitAndCriteria(JobMatchParser.AndCriteriaContext ctx) {
				List<Criteria<io.onedev.server.job.match.JobMatchContext>> childCriterias = new ArrayList<>();
				for (JobMatchParser.CriteriaContext childCtx: ctx.criteria())
					childCriterias.add(visit(childCtx));

View on GitHub (pinned to d44925c47c)

Solutions

  1. Use only supported operators for value criteria in this context (e.g. 'on branch "main"')
  2. Rewrite the condition with an explicitly supported field/operator combination
  3. Update OneDev if a newer version supports the desired operator
  4. Restructure the expression so the unsupported operator applies to a criteria form that handles it

Example fix

// before
// match: "commit is abc123"
// after
// match: "on branch main"
Defensive patterns

Strategy: validation

Validate before calling

// restrict value-criteria expressions to supported operators, e.g.
// "on branch main" instead of "commit is abc"

Try / catch

try {
    var match = JobMatch.parse(expr, false, false);
} catch (ExplicitException e) {
    if (e.getMessage().startsWith("Unexpected operator")) {
        // replace unsupported operator with a supported one
    }
}

Prevention

When it happens

Trigger: A job match expression of the form 'field operator "value"' where operator is not OnBranch — e.g. 'commit is abc' or another operator not mapped in visitOperatorValueCriteria's switch.

Common situations: Writing a match expression using an operator valid elsewhere (e.g. in build queries) but unsupported in this job match position; grammar evolved faster than the visitor; hand-editing expressions without the UI validator.

Related errors


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