ToolJet/ToolJet · error · QueryError

Query could not be completed

Error message

Query could not be completed

What it means

The CosmosDB plugin's run() wraps every operation (listDatabases, listContainers, insertItems, deleteItem, queryDatabase, getItem) in one try/catch and rethrows any failure as QueryError('Query could not be completed', error.message, {}). The original SDK error message is preserved as the description; the structured ErrorResponse (code, status, substatus) is discarded.

Source

Thrown at plugins/packages/cosmosdb/lib/index.ts:45

        case 'delete_item':
          result = await deleteItem(
            client,
            queryOptions.database,
            queryOptions.container,
            queryOptions.itemId,
            queryOptions?.partitionKey
          );
          break;
        case 'query_database':
          result = await queryDatabase(client, queryOptions.database, queryOptions.container, queryOptions.query);
          break;

        default:
          break;
      }
    } catch (error) {
      console.log(error);
      throw new QueryError('Query could not be completed', error.message, {});
    }

    return {
      status: 'ok',
      data: result,
    };
  }

  async testConnection(sourceOptions: SourceOptions): Promise<ConnectionTestResult> {
    const { endpoint, key } = sourceOptions;
    const genericClient = new CosmosClient({ endpoint, key });

    await genericClient.getDatabaseAccount();
    return {
      status: 'ok',
    };
  }

View on GitHub (pinned to 20602a8e10)

Solutions

  1. Read error.description for the SDK message (e.g. 'Resource Not Found', 'Entity with the specified id does not exist').
  2. Verify sourceOptions endpoint and key via testConnection first.
  3. Confirm the database and container names in queryOptions exist in the account.
  4. For delete/read operations, supply the partition key when the container is partitioned.
  5. For 429 throttling, raise provisioned RU/s or retry with backoff; reduce query cost.

Example fix

// before - delete without partition key on a partitioned container
await deleteItem(client, db, container, itemId);
// after - supply the partition key
await deleteItem(client, db, container, itemId, partitionKey);
Defensive patterns

Strategy: try-catch

Validate before calling

function validateCosmosOptions(sourceOptions: any) {
  if (!sourceOptions?.endpoint || !/^https:///.test(sourceOptions.endpoint)) {
    throw new Error('CosmosDB endpoint must be an https:// URL');
  }
  if (!sourceOptions?.key) throw new Error('CosmosDB key is required');
  if (!queryOptions?.database || !queryOptions?.container) {
    throw new Error('database and container are required for this operation');
  }
}

Type guard

function isCosmosResourceNotFoundError(err: any): boolean {
  return err?.code === 404 || /not found/i.test(err?.message ?? '');
}

Try / catch

try {
  return await cosmosdb.run(sourceOptions, queryOptions, ...);
} catch (err) {
  if (err instanceof QueryError && err.description) {
    if (/404|not found/i.test(err.description)) return { status: 'ok', data: [] };
    if (/429|throttl/i.test(err.description)) return retryWithBackoff(() => cosmosdb.run(...));
  }
  throw err;
}

Prevention

When it happens

Trigger: Any CosmosClient failure: invalid endpoint/key, a non-existent database/container id, a malformed SQL query, a missing partition key on a partitioned container delete/read, request throttling (429), or a transient network/TLS error.

Common situations: Wrong CosmosDB endpoint URL or primary key, querying a container that does not exist, deleting an item without supplying the required partition key, hitting RU/s throttle limits, or a typo in the SQL query string.

Related errors


AI-assisted analysis of ToolJet/ToolJet@20602a8e10 (2026-08-13). Data as JSON: /api/errors/cd5494a8f2bc6a22. Report an issue: GitHub.