can1357/oh-my-pi · error · ToolError
SQLite order direction must be 'asc' or 'desc'; got
Error message
SQLite order direction must be 'asc' or 'desc'; got '${direction}' What it means
Thrown by resolveOrderClause when the direction suffix of the 'order' parameter is not exactly 'asc' or 'desc' (after trimming and lowercasing). The tool whitelists directions so only validated, safe ORDER BY clauses are built.
Solutions
- Use 'asc' or 'desc' as the direction suffix
- Omit the direction entirely (defaults to 'asc')
- Check the separator format: order is 'column[:direction]'
- Strip whitespace — trailing text after asc/desc still fails
Example fix
// before ?order=created_at:ascending // after ?order=created_at:desc
Defensive patterns
Strategy: validation
Validate before calling
const dir = (orderDirection ?? 'asc').trim().toLowerCase();
if (dir !== 'asc' && dir !== 'desc') {
throw new Error(`direction must be asc|desc, got '${dir}'`);
} Type guard
function isSortDirection(v: string): v is 'asc' | 'desc' {
return v === 'asc' || v === 'desc';
} Try / catch
try {
await reader.read(`db.sqlite/users?order=name:${dir}`);
} catch (err) {
if (err instanceof ToolError && err.message.includes("must be 'asc' or 'desc'")) {
// retry with default direction
} else throw err;
} Prevention
- Normalize direction input with trim().toLowerCase() before building the URL
- Constrain direction to a union type 'asc'|'desc' in your own code
- Omit the direction suffix when you want ascending
When it happens
Trigger: Passing order like 'name:ASCENDING', 'name:1', 'name:up', or 'name:' with a junk/empty direction suffix after the ':' separator.
Common situations: Copy-pasting SQL-style direction keywords ('ASCENDING', 'ascending', 'ascending order'); using numeric sort direction codes; locale issues where a direction word got translated.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- must be an integer; got
- SQLite column ' ' only accepts JSON scalar values or null
- SQLite limit must be a positive integer; got
- SQLite offset must be a non-negative integer; got
- SQLite order column ' ' not found in table schema
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/b147731aa0c72cd7.
Report an issue: GitHub.
Appendix: source
Thrown at packages/coding-agent/src/tools/sqlite-reader.ts:390
function resolveOrderClause(order: string | undefined, columns: string[]): string {
if (!order) return "";
const trimmed = order.trim();
if (!trimmed) return "";
const separatorIndex = trimmed.lastIndexOf(":");
const column = separatorIndex === -1 ? trimmed : trimmed.slice(0, separatorIndex);
const direction =
separatorIndex === -1
? "asc"
: trimmed
.slice(separatorIndex + 1)
.trim()
.toLowerCase();
if (!columns.includes(column)) {
throw new ToolError(`SQLite order column '${column}' not found in table schema`);
}
if (direction !== "asc" && direction !== "desc") {
throw new ToolError(`SQLite order direction must be 'asc' or 'desc'; got '${direction}'`);
}
return ` ORDER BY ${quoteSqliteIdentifier(column)} ${direction.toUpperCase()}`;
}
const FORBIDDEN_WHERE_KEYWORDS = new Set([
"limit",
"offset",
"union",
"intersect",
"except",
"attach",
"detach",
"pragma",
]);
const COMMENT_OR_TERMINATOR_ERROR =
"SQLite 'where' clause must not contain comments or statement terminators; use '?q=SELECT ...' for raw SQL";
const FORBIDDEN_KEYWORD_ERROR =View on GitHub (pinned to 9690622007)