bytebase/bytebase · error
invalid order_by entry %q
Error message
invalid order_by entry %q
What it means
getOrderByKeys parses a comma-separated order_by string where each entry must be 'column' or 'column asc|desc' (at most two whitespace-separated parts). An entry that is empty after splitting or has more than two tokens (e.g. an embedded third word) is rejected with this error quoting the raw entry.
Source
Thrown at backend/store/common.go:54
SortOrder SortOrder
}
// getOrderByKeys parses an AIP-132 order_by string against a whitelist
// mapping API field names to SQL columns. Strict where parseOrderBy is not:
// every comma-separated entry must be a whitelisted field with an optional
// "asc"/"desc" suffix, and a repeated field is rejected — malformed input
// errors instead of being silently reinterpreted.
func getOrderByKeys(orderBy string, columns map[string]string) ([]*OrderByKey, error) {
if orderBy == "" {
return nil, nil
}
var result []*OrderByKey
seen := make(map[string]bool)
for entry := range strings.SplitSeq(orderBy, ",") {
parts := strings.Fields(entry)
if len(parts) == 0 || len(parts) > 2 {
return nil, errors.Errorf("invalid order_by entry %q", strings.TrimSpace(entry))
}
column, ok := columns[parts[0]]
if !ok {
return nil, errors.Errorf("unsupported order field %q", parts[0])
}
if seen[parts[0]] {
return nil, errors.Errorf("duplicate order field %q", parts[0])
}
seen[parts[0]] = true
sortOrder := ASC
if len(parts) == 2 {
switch parts[1] {
case "asc":
case "desc":
sortOrder = DESC
default:
return nil, errors.Errorf("invalid order direction %q, expect asc or desc", parts[1])
}View on GitHub (pinned to 1870550677)
Solutions
- Use entries of the form 'column' or 'column asc|desc' separated by single commas, e.g. "update_time desc, create_time".
- Strip trailing commas and collapse whitespace before sending.
- Only use columns from the endpoint's allowed set (this specific message is about token shape; a bad column yields the separate 'unsupported order field' error).
Example fix
// before orderBy := "create_time desc asc, " // 3 tokens + empty entry // after orderBy := "create_time desc"
Defensive patterns
Strategy: validation
Validate before calling
const entries = orderBy.split(",");
for (const e of entries) {
const parts = e.trim().split(/\s+/).filter(Boolean);
if (parts.length === 0 || parts.length > 2) throw new Error(`invalid order_by entry: "${e.trim()}"`);
} Try / catch
try { return await listSavedQueries({ orderBy }); } catch (e) { if (String(e).includes("invalid order_by entry")) { throw new Error("Each entry must be 'column' or 'column asc|desc'"); } throw e; } Prevention
- Trim each entry and collapse internal whitespace before sending
- Strip trailing commas from programmatic order_by strings
- Emit at most one direction word (asc/desc) per column
- Build order_by from a typed array of {column, direction} instead of raw strings
When it happens
Trigger: order_by strings like "create_time desc asc", "create_time desc extra", "update_time DESC, " (trailing comma yielding an empty entry) passed to GetSavedQueryOrders or other consumers.
Common situations: Trailing commas in hand-built order_by; users typing 'order by create time descending' in prose form; double spaces creating empty tokens when combined with stray words; programmatic builders appending both direction words.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- only support order by "create_time"
- auth.sso.unsupported-provider-type
- Invalid changelog name
- common.error
- failed to build CEL expression
AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06).
Data as JSON: /api/errors/2cfee77cda81bc05.
Report an issue: GitHub.