Troubleshooting
The query returns an error object instead of throwing
VQLProcessor.execute() never throws for query failures. It returns a VQLError. Check the result:
import { isVQLError } from "@wxn0brp/vql";
const result = await processor.execute(query, user);
if (isVQLError(result)) {
console.error(result.code, result.message, result.suggestion);
}
See Errors.
Database "x" not found
The first argument to VQLProcessor is a name map:
new VQLProcessor({
main: dbMain,
analytics: dbAnalytics
});
Queries use those names exactly:
main users
Relation paths also use registered names: path: ["analytics", "events"].
"Invalid VQL query structure. Must contain 'r' or 'db' and 'd'."
The object has neither r nor a db + d pair.
// Invalid
{ db: "main" }
// Valid
{ db: "main", d: { find: { collection: "users" } } }
{ r: { path: ["main", "users"], search: {}, relations: {} } }
Validation errors
| Message | Fix |
|---|---|
CRUD operation 'x' must specify a non-empty 'collection' string. |
Add a collection name |
'findOne' operation requires a 'search' object. |
Add search: {} even for a match-all |
'update' operation requires an 'updater' object. |
Add updater |
'bulkAdd' operation requires a 'datas' array. |
Use an array |
'find' operation 'select' property must be an object or an array. |
Use ["name"] or { name: 1 }. The operation name is part of the message |
Relation query 'r.search' must be an object. |
Add search: {} |
Relation query 'r' must have a 'relations' object. |
Add relations: {} |
Relation 'x' has an invalid 'select' property; it must be an array. |
Use select: ["name"] |
Database "x" not found |
Register the name in the processor |
Query returns an empty array
Check the search shape. Some operators expect nested field objects:
// Wrong: this asks for a field called "$gt"
{ "$gt": 18 }
// Right
{ $gt: { age: 18 } }
Other causes:
s.age>18in VQLS becomes{ $gt: { age: 18 } }, not a plain equality.- Numeric strings must be quoted:
s.externalId="123". selectdoes not filter records, it only projects fields.options.limitlimits results. A top-levellimitis ignored.- If you sort with
sortByand also useselect, include the sort field in the selection. Removing it can make the sort ineffective. - A relation query with
many: falsereturns one record ornull.
Fields are missing from the result
selectkeeps only the listed fields.searchOpts.excluderemoves fields.- With permissions enabled, fields without
READare removed. - VQLS
e.profile.city=1selects the wholeprofilefor CRUD operations. Use VQLR for a nested CRUD selection.
Permission denied
Common causes:
- No user context.
permissionDeniedIfNoUserdefaults totrue. Onlynullis denied;undefinedis replaced by the placeholder{ _id: "null-null-null" }and continues with a fake identity. Always pass a real user object. strictSelectmissing. Enabling permissions withoutstrictSelect: truethrowsVQLConfigErrorat construction.- Path mismatch. Permission paths are
[database, collection, ...field]. Check the exact spelling and casing. hidePathmismatch. WithhidePath: true,args.fieldis a SHA-256 hash. Rules registered with plain paths will not match.- No resolver match.
PermissionResolverEnginedenies when nothing matches. Add astartsWithor regex matcher, or usecreateWithGw. - Gate Warden user missing.
createGwValidFnloads the user from the Gate Warden database. A missing user is reported asuser-404. entity-404withstrictACL: true. Register the exact path or disable strict ACL to allow parent fallback.
Inspect the permission arguments:
const permValidFn = async args => {
console.dir(args);
return { granted: false };
};
Permission checks do not run
noCheckPermissionsdefaults totrue. Set it tofalse.LowAdapterresolvers bypass the permission layer. Authorize inside the resolver.- If you pass a custom
permValidFnthat always returns{ granted: true }, every request is allowed.
Relation errors
pathmust be exactly two strings:["db", "collection"].searchandrelationsmust exist, even when empty.- Relation
selectis an array. In VQLS use JSON:r.items.select=["name"]. - A missing database in any relation
paththrowsVQLDBNotFoundError. A badthrough.dbis not pre-checked and fails later withVQLInternalError. type: "nm"requiresthrough.table,through.pk, andthrough.fk.
See Relations.
VQLS parsing surprises
| Input | Result | Reason |
|---|---|---|
db removeOne users! s._id="1" |
Collection users! |
Explicit operations do not strip ! |
s.active= followed by another key |
Wrong pair | Empty value consumes the next token |
s.name=Alice |
String "Alice" |
Unquoted values stay strings |
s.id=123 |
Number 123 |
Quote to keep as string |
s.date=null |
String "null" |
Use JSON: s={"date":null} |
s.a.b>1 |
{ $gt: { a: { b: 1 } } } |
Operators are applied operator-first |
s={"a": 1} |
Parsed incorrectly | JSON values must be compact |
r.orders.search.status="pending" |
Accepted but not applied | The relation loader ignores per-relation search |
e.profile.city=1 |
Selects profile |
CRUD selects collapse to top level |
Quoted values are needed for spaces, =, <, and >.
HTTP endpoint returns 500
- The processor is returning a
VQLInternalErrorfrom an unexpected exception. Enable logging atDEBUGand inspect the error. - A custom adapter threw.
AdapterBuilderswallows handler errors intoundefined; pass acatchCbthat logs. - Falcon Frame did not parse the body. Make sure the request is JSON and the body uses the
querykey, or providegetQuery.
A 501 means no adapter handler exists for that operation and collection. Register one or add a "*" handler.
TypeScript cannot find VQLUQ or VQL_Query
Types are published under subpaths, not the package root:
import type { VQLUQ, VQL_Query } from "@wxn0brp/vql/types/vql";
Permission types:
import { PermCRUD } from "@wxn0brp/vql/types/perm";
Debug logging
import { VQLLogger, VQLLogLevel } from "@wxn0brp/vql";
VQLLogger.logLevel = VQLLogLevel.DEBUG;
The logger prints incoming queries, expanded queries, validation failures, and internal errors. It may include user data, so disable it in production.
Still stuck
Capture the failing query, the config, and the user context. Run the query through processor._preProcessQuery(query, user) to see whether it fails before execution:
const prepared = processor._preProcessQuery(query, user);
console.dir(prepared, { depth: null });