theonedev/onedev · error · ExplicitException
Cannot order by field: ${fieldName}
Error message
Cannot order by field: ${fieldName} What it means
ProjectQuery.parse resolves each 'order by' field name against the static SORT_FIELDS map; unknown names throw ExplicitException('Cannot order by field: X'). Only whitelisted sortable fields (e.g. name, last activity) may be used in 'order by'.
Source
Thrown at server-core/src/main/java/io/onedev/server/search/entity/project/ProjectQuery.java:241
return new AndCriteria<>(childCriterias);
}
@Override
public Criteria<Project> visitNotCriteria(NotCriteriaContext ctx) {
return new NotCriteria<>(visit(ctx.criteria()));
}
}.visit(criteriaContext);
} else {
projectCriteria = null;
}
List<EntitySort> projectSorts = 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 projectSort = new EntitySort();
projectSort.setField(fieldName);
if (order.direction != null) {
if (order.direction.getText().equals("desc"))
projectSort.setDirection(DESCENDING);
else
projectSort.setDirection(ASCENDING);
} else {
projectSort.setDirection(sortField.getDefaultDirection());
}
projectSorts.add(projectSort);
}
return new ProjectQuery(projectCriteria, projectSorts);
} else {
return new ProjectQuery();
}View on GitHub (pinned to d44925c47c)
Solutions
- Order only by fields listed in ProjectQuery.SORT_FIELDS (e.g. "name", "last activity").
- Drop the order-by clause and sort results client-side if the field is unsupported.
- Catch ExplicitException and present allowed sort fields to the user.
- Correct the field-name spelling/casing to match the whitelist exactly.
Example fix
// before "... order by \"description\"" // not sortable // after "... order by \"name\" desc"
Defensive patterns
Strategy: validation
Validate before calling
// pre-check sort field
if (!Set.of("name", "last activity").contains(sortField)) throw new IllegalArgumentException("Not sortable: " + sortField); Type guard
null
Try / catch
try { q = ProjectQuery.parse(text); } catch (ExplicitException e) { showAllowedSortFields(e); } Prevention
- Order only by fields present in ProjectQuery.SORT_FIELDS
- Do not assume filterable fields are sortable
- Sort client-side when the field is unsupported
- Validate order-by clauses in saved query editors
When it happens
Trigger: A query ending in 'order by "someField"' where someField is queryable but not in ProjectQuery.SORT_FIELDS.
Common situations: Sorting by fields that are filterable but not sortable (e.g. description); typos in field names; queries ported from other entity types with different sort fields.
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
- Field not found: ${fieldName}
- Criteria '${operator}' is not supported here
- Unexpected operator: ${operator}
- Unexpected criteria: ${operator}
- Cannot order by field: ${fieldName}
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/1b8bf3fbbd4cf432.
Report an issue: GitHub.