{"record":{"id":"cd5494a8f2bc6a22","repo":"ToolJet/ToolJet","slug":"query-could-not-be-completed-cd5494","errorCode":null,"errorMessage":"Query could not be completed","messagePattern":"Query could not be completed","errorType":"exception","errorClass":"QueryError","httpStatus":null,"severity":"error","filePath":"plugins/packages/cosmosdb/lib/index.ts","lineNumber":45,"sourceCode":"        case 'delete_item':\n          result = await deleteItem(\n            client,\n            queryOptions.database,\n            queryOptions.container,\n            queryOptions.itemId,\n            queryOptions?.partitionKey\n          );\n          break;\n        case 'query_database':\n          result = await queryDatabase(client, queryOptions.database, queryOptions.container, queryOptions.query);\n          break;\n\n        default:\n          break;\n      }\n    } catch (error) {\n      console.log(error);\n      throw new QueryError('Query could not be completed', error.message, {});\n    }\n\n    return {\n      status: 'ok',\n      data: result,\n    };\n  }\n\n  async testConnection(sourceOptions: SourceOptions): Promise<ConnectionTestResult> {\n    const { endpoint, key } = sourceOptions;\n    const genericClient = new CosmosClient({ endpoint, key });\n\n    await genericClient.getDatabaseAccount();\n    return {\n      status: 'ok',\n    };\n  }\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/ToolJet/ToolJet/blob/20602a8e101f2e59686c9afde0d1402aac2c8871/plugins/packages/cosmosdb/lib/index.ts#L27-L63","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read error.description for the SDK message (e.g. 'Resource Not Found', 'Entity with the specified id does not exist').","Verify sourceOptions endpoint and key via testConnection first.","Confirm the database and container names in queryOptions exist in the account.","For delete/read operations, supply the partition key when the container is partitioned.","For 429 throttling, raise provisioned RU/s or retry with backoff; reduce query cost."],"exampleFix":"// before - delete without partition key on a partitioned container\nawait deleteItem(client, db, container, itemId);\n// after - supply the partition key\nawait deleteItem(client, db, container, itemId, partitionKey);","handlingStrategy":"try-catch","validationCode":"function validateCosmosOptions(sourceOptions: any) {\n  if (!sourceOptions?.endpoint || !/^https:///.test(sourceOptions.endpoint)) {\n    throw new Error('CosmosDB endpoint must be an https:// URL');\n  }\n  if (!sourceOptions?.key) throw new Error('CosmosDB key is required');\n  if (!queryOptions?.database || !queryOptions?.container) {\n    throw new Error('database and container are required for this operation');\n  }\n}","typeGuard":"function isCosmosResourceNotFoundError(err: any): boolean {\n  return err?.code === 404 || /not found/i.test(err?.message ?? '');\n}","tryCatchPattern":"try {\n  return await cosmosdb.run(sourceOptions, queryOptions, ...);\n} catch (err) {\n  if (err instanceof QueryError && err.description) {\n    if (/404|not found/i.test(err.description)) return { status: 'ok', data: [] };\n    if (/429|throttl/i.test(err.description)) return retryWithBackoff(() => cosmosdb.run(...));\n  }\n  throw err;\n}","preventionTips":["Run testConnection before issuing queries to fail fast on bad credentials.","Always pass the partition key for partitioned-container read/delete operations.","Verify database/container names exist before querying them.","Handle 429 throttling with retry-after backoff rather than surfacing as an error.","Validate the endpoint is https and the key is non-empty."],"tags":["cosmosdb","azure","database","query"],"backgroundTag":null,"analyzedSha":"20602a8e101f2e59686c9afde0d1402aac2c8871","analyzedAt":"2026-08-13T05:58:54.221Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}