theonedev/onedev · error · ExplicitException
"Cannot order by field: " + fieldName
Error message
"Cannot order by field: " + fieldName
What it means
Query-parser guard in WorkspaceQuery.parse: the query's order-by clause names a field not present in SORT_FIELDS, so the sort cannot be translated to an index field; ExplicitException reports the offending fieldName. Fix: order by one of the supported workspace query fields.
Source
Thrown at server-core/src/main/java/io/onedev/server/search/entity/workspace/WorkspaceQuery.java:260
return new AndCriteria<>(childCriterias);
}
@Override
public Criteria<Workspace> visitNotCriteria(NotCriteriaContext ctx) {
return new NotCriteria<>(visit(ctx.criteria()));
}
}.visit(criteriaContext);
} else {
workspaceCriteria = null;
}
List<EntitySort> workspaceSorts = new ArrayList<>();
for (OrderContext order : queryContext.order()) {
var fieldName = getValue(order.Quoted().getText());
var sortField = SORT_FIELDS.get(fieldName);
if (sortField == null)
throw new ExplicitException("Cannot order by field: " + fieldName);
EntitySort workspaceSort = new EntitySort();
workspaceSort.setField(fieldName);
if (order.direction != null) {
if (order.direction.getText().equals("desc"))
workspaceSort.setDirection(DESCENDING);
else
workspaceSort.setDirection(ASCENDING);
} else {
workspaceSort.setDirection(sortField.getDefaultDirection());
}
workspaceSorts.add(workspaceSort);
}
return new WorkspaceQuery(workspaceCriteria, workspaceSorts);
} else {
return new WorkspaceQuery();
}View on GitHub (pinned to d44925c47c)
Solutions
- Order only by sortable fields listed in WorkspaceQuery.SORT_FIELDS (e.g. "number", "name", "submit date").
- Remove the order by clause to use default ordering.
- Fix the field name spelling.
Example fix
// before
order by ("commit")
// after
order by ("submit date") desc Defensive patterns
Strategy: validation
Validate before calling
Set<String> sortableFields = Set.of("number", "name", "submit date", "create date", "active date");
if (!sortableFields.contains(orderField)) throw new IllegalArgumentException("Cannot order by " + orderField); Try / catch
try {
var query = WorkspaceQuery.parse(queryText);
} catch (ExplicitException e) {
// drop or fix the order by clause
} Prevention
- Order only by fields in WorkspaceQuery.SORT_FIELDS
- Use default ordering when unsure
When it happens
Trigger: A query with an `order by` clause naming a field not in SORT_FIELDS, e.g. `order by ("commit")`.
Common situations: Sorting by fields that exist as query criteria but not as sortable fields; typos in sort field names; reusing sort fields from other entity queries.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- "Criteria '" + ctx.operator.getText() + "' is not supported
- "Unexpected operator: " + ctx.operator.getText()
- "Unexpected field: " + fieldName
- "Field not found: " + fieldName
- Count should not be greater than ${MAX_PAGE_SIZE}
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/0197548c30c1a294.
Report an issue: GitHub.