{"record":{"id":"7ad78aa61ee2677c","repo":"theonedev/onedev","slug":"cannot-order-by-field-fieldname","errorCode":null,"errorMessage":"Cannot order by field: ${fieldName}","messagePattern":"Cannot order by field: (.+?)","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/pack/PackQuery.java","lineNumber":210,"sourceCode":"\t\t\t\t\t\treturn new AndCriteria<>(childCriterias);\n\t\t\t\t\t}\n\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic Criteria<Pack> visitNotCriteria(NotCriteriaContext ctx) {\n\t\t\t\t\t\treturn new NotCriteria<>(visit(ctx.criteria()));\n\t\t\t\t\t}\n\n\t\t\t\t}.visit(criteriaContext);\n\t\t\t} else {\n\t\t\t\tpackCriteria = null;\n\t\t\t}\n\n\t\t\tList<EntitySort> buildSorts = new ArrayList<>();\n\t\t\tfor (OrderContext order: queryContext.order()) {\n\t\t\t\tvar fieldName = getValue(order.Quoted().getText());\n\t\t\t\tvar sortField = SORT_FIELDS.get(fieldName);\n\t\t\t\tif (sortField == null)\n\t\t\t\t\tthrow new ExplicitException(\"Cannot order by field: \" + fieldName);\n\t\t\t\t\n\t\t\t\tEntitySort packSort = new EntitySort();\n\t\t\t\tpackSort.setField(fieldName);\n\t\t\t\tif (order.direction != null) {\n\t\t\t\t\tif (order.direction.getText().equals(\"desc\"))\n\t\t\t\t\t\tpackSort.setDirection(DESCENDING);\n\t\t\t\t\telse\n\t\t\t\t\t\tpackSort.setDirection(ASCENDING);\n\t\t\t\t} else {\n\t\t\t\t\tpackSort.setDirection(sortField.getDefaultDirection());\n\t\t\t\t}\n\t\t\t\tbuildSorts.add(packSort);\n\t\t\t}\n\t\t\t\n\t\t\treturn new PackQuery(packCriteria, buildSorts);\n\t\t} else {\n\t\t\treturn new PackQuery();\n\t\t}","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/pack/PackQuery.java#L192-L228","documentation":"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>\").","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n\"order by \"publisher\"\"\n// after\n\"order by \"publish date\"\" // a field present in SORT_FIELDS","handlingStrategy":"validation","validationCode":"function validateSortField(f) { const sortable = ['publish date']; /* keys of PackQuery.SORT_FIELDS */ if (!sortable.includes(f)) throw new Error('Cannot order by field: ' + f); }","typeGuard":"null","tryCatchPattern":"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; }","preventionTips":["Only order by fields listed in PackQuery.SORT_FIELDS","Distinguish filterable vs sortable fields","Consult UI autocomplete for sort field names"],"tags":["query","validation","sort","onedev"],"backgroundTag":"invalid-query-parameter","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}