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

  1. Order only by fields listed in ProjectQuery.SORT_FIELDS (e.g. "name", "last activity").
  2. Drop the order-by clause and sort results client-side if the field is unsupported.
  3. Catch ExplicitException and present allowed sort fields to the user.
  4. 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

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


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