theonedev/onedev · error · ExplicitException
Cannot order by field: ${fieldName}
Error message
Cannot order by field: ${fieldName} What it means
PackQuery.parse validates every order-by field against SORT_FIELDS. If a fieldName from the query's order clause is not a sortable field, it throws ExplicitException("Cannot order by field: <fieldName>").
Source
Thrown at server-core/src/main/java/io/onedev/server/search/entity/pack/PackQuery.java:210
return new AndCriteria<>(childCriterias);
}
@Override
public Criteria<Pack> visitNotCriteria(NotCriteriaContext ctx) {
return new NotCriteria<>(visit(ctx.criteria()));
}
}.visit(criteriaContext);
} else {
packCriteria = null;
}
List<EntitySort> buildSorts = 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 packSort = new EntitySort();
packSort.setField(fieldName);
if (order.direction != null) {
if (order.direction.getText().equals("desc"))
packSort.setDirection(DESCENDING);
else
packSort.setDirection(ASCENDING);
} else {
packSort.setDirection(sortField.getDefaultDirection());
}
buildSorts.add(packSort);
}
return new PackQuery(packCriteria, buildSorts);
} else {
return new PackQuery();
}View on GitHub (pinned to d44925c47c)
Solutions
- Use one of the documented sortable fields for packs (e.g. the publish date/name fields defined in SORT_FIELDS)
- Check PackQuery.SORT_FIELDS keys for exact allowed names
- Catch ExplicitException and list valid sort fields in the error message shown to users
Example fix
// before "order by "publisher"" // after "order by "publish date"" // a field present in SORT_FIELDS
Defensive patterns
Strategy: validation
Validate before calling
function validateSortField(f) { const sortable = ['publish date']; /* keys of PackQuery.SORT_FIELDS */ if (!sortable.includes(f)) throw new Error('Cannot order by field: ' + f); } Type guard
null
Try / catch
try { PackQuery.parse(project, q); } catch (ExplicitException e) { if (e.getMessage().startsWith('Cannot order by field')) showError('Valid sort fields: publish date'); else throw e; } Prevention
- Only order by fields listed in PackQuery.SORT_FIELDS
- Distinguish filterable vs sortable fields
- Consult UI autocomplete for sort field names
When it happens
Trigger: Parsing a pack query with an 'order by <field>' clause where <field> is not a key in SORT_FIELDS — misspelled field names, or fields that are queryable but not sortable.
Common situations: Users ordering by a field that exists as a filter but not as a sort field; typos ('publish date' vs correct name); copying order clauses from other entity queries.
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
- Criteria '${operator}' is not supported here
- Unexpected operator: ${operator}
- Unexpected criteria: ${operator}
- Field not found: ${fieldName}
- Invalid number: ${value}
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/7ad78aa61ee2677c.
Report an issue: GitHub.