pubkey/rxdb · error · RxError
QU18
QU18
Error message
RxDB Error-Code: QU18. Hint: Error messages are not included in RxDB core to reduce build size. To show the full error messages and to ensure that you do not make any mistakes when using RxDB, use the dev-mode plugin when you are in development mode: https://rxdb.info/dev-mode.html?console=error
What it means
QU18 is thrown by RxQuery._setResultData when the storage layer returns undefined as the query result. RxDB expects either an array of documents, a number (for counts), or a Map; undefined means the storage instance returned an invalid result, so RxDB surfaces QU18 naming the database and collection.
Source
Thrown at src/rx-query.ts:248
*/
public _ensureEqualQueue: Promise<boolean> = PROMISE_RESOLVE_FALSE;
/**
* Returns an observable that emits the results
* This should behave like an rxjs-BehaviorSubject which means:
* - Emit the current result-set on subscribe
* - Emit the new result-set when an RxChangeEvent comes in
* - Do not emit anything before the first result-set was created (no null)
*/
public _$?: Observable<RxQueryResult>;
/**
* set the new result-data as result-docs of the query
* @param newResultData json-docs that were received from the storage
*/
_setResultData(newResultData: RxDocumentData<RxDocType>[] | number | Map<string, RxDocumentData<RxDocType>>): void {
if (typeof newResultData === 'undefined') {
throw newRxError('QU18', {
database: this.collection.database.name,
collection: this.collection.name
});
}
if (typeof newResultData === 'number') {
this._result = new RxQuerySingleResult<RxDocType>(
this as any,
[],
newResultData
);
return;
} else if (newResultData instanceof Map) {
newResultData = Array.from((newResultData as Map<string, RxDocumentData<RxDocType>>).values());
}
const newQueryResult = new RxQuerySingleResult<RxDocType>(
this as any,
newResultData,View on GitHub (pinned to af6fb65f94)
Solutions
- Inspect the RxStorage implementation used by this collection and ensure query()/count() always resolve with RxDocumentData[] , number, or Map, including all early-return paths.
- Add a regression test in the storage plugin that every query branch returns a defined value.
- Check that the storage plugin version is compatible with the installed RxDB core version and update both together.
- Wrap the storage call chain in logging to capture the resolved value before it reaches _setResultData.
Example fix
// before (custom storage)
async query(preparedQuery) {
if (cached) return cached;
// missing return on the slow path
this.underlying.query(preparedQuery);
}
// after
async query(preparedQuery) {
if (cached) return cached;
return this.underlying.query(preparedQuery);
} Defensive patterns
Strategy: try-catch
Validate before calling
const result = await storageInstance.query(preparedQuery);
if (typeof result === 'undefined') {
throw new Error('storage query() returned undefined - fix the RxStorage implementation');
} Type guard
function isValidStorageResult<T>(r: unknown): r is RxDocumentData<T>[] | number | Map<string, RxDocumentData<T>> {
return Array.isArray(r) || typeof r === 'number' || r instanceof Map;
} Try / catch
try {
const docs = await query.exec();
} catch (err) {
if (err?.code === 'QU18') {
console.error(`storage for ${err.parameters?.database}/${err.parameters?.collection} returned undefined`);
throw new Error('invalid RxStorage plugin result');
}
throw err;
} Prevention
- When writing custom RxStorage plugins, return a value from every branch of query()/count().
- Keep storage plugin versions in lockstep with the RxDB core version.
- Add automated storage-conformance tests that assert defined results for all query shapes.
When it happens
Trigger: A custom RxStorage plugin's query()/count() implementation resolves with undefined (e.g. a missing return statement, an async function returning nothing, or a wrapper that swallows the result).
Common situations: Developing or upgrading a custom RxStorage backend; wrapping the storage instance with caching/proxy code that drops return values; version mismatch where a storage plugin returns a shape the core no longer expects.
Related errors
AI-assisted analysis of pubkey/rxdb@af6fb65f94 (2026-08-31).
Data as JSON: /api/errors/49b37e60c1b7642c.
Report an issue: GitHub.