{"record":{"id":"1a7cfca981967d2e","repo":"cube-js/cube","slug":"priority-should-be-between-10000-and-10000","errorCode":null,"errorMessage":"Priority should be between -10000 and 10000","messagePattern":"Priority should be between -10000 and 10000","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-query-orchestrator/src/orchestrator/QueryQueue.ts","lineNumber":248,"sourceCode":"        queryKey: queryDef.queryKey,\n        queuePrefix: this.redisQueuePrefix,\n        requestId: options.requestId,\n        waitingForRequestId: queryDef.requestId\n      });\n      if (queryHandler === 'stream') {\n        throw new Error('Streaming queries to Cube Store aren\\'t supported');\n      }\n      const result = await this.processQuerySkipQueue(queryDef, options.queueId);\n      return this.parseResult(result);\n    }\n\n    const queueConnection = await this.queueDriver.createConnection();\n    let waitingContext;\n    let streamWait: QueryStreamWait | null = null;\n\n    try {\n      if (!(priority >= -10000 && priority <= 10000)) {\n        throw new Error('Priority should be between -10000 and 10000');\n      }\n\n      // Result here won't be fetched for a forced build query and a jobbed build\n      // query (initialized by the /cubejs-system/v1/pre-aggregations/jobs\n      // endpoint).\n      let result = !query.forceBuild && await queueConnection.getResult(queryKey, options.externalId);\n      if (result && !result.streamResult) {\n        return this.parseResult(result);\n      }\n\n      const queryKeyHash = this.redisHash(queryKey);\n\n      if (query.forceBuild) {\n        const jobExists = await queueConnection.getQueryDef(queryKeyHash, null);\n        if (jobExists) return null;\n      }\n\n      options.orphanedTimeout = query.orphanedTimeout;","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-query-orchestrator/src/orchestrator/QueryQueue.ts#L230-L266","documentation":"QueryQueue validates that the priority passed to executeInQueue is a number within [-10000, 10000]. Out-of-range (or NaN) priorities would corrupt queue ordering in Redis, so the queue throws immediately after opening the connection.","triggerScenarios":"Calling executeInQueue / executeInQueueSkipQueue with priority < -10000, > 10000, undefined/NaN, or a non-numeric value (NaN fails the >= -10000 check).","commonSituations":"Hard-coded extreme priorities like 99999 in custom orchestration code; priority read from config as a string; arithmetic on an undefined variable yielding NaN.","solutions":["Clamp or correct the priority value to be within -10000..10000 before calling executeInQueue","Coerce config/env-supplied values with Number() and validate before use","Use the library's own priority constants (e.g. QUERY_PRIORITY constants) instead of ad-hoc numbers"],"exampleFix":"// before\nconst priority = Number(process.env.QUERY_PRIORITY); // undefined -> NaN\nawait queue.executeInQueue(handler, key, query, priority, options);\n// after\nconst priority = Math.max(-10000, Math.min(10000, Number(process.env.QUERY_PRIORITY) || 0));\nawait queue.executeInQueue(handler, key, query, priority, options);","handlingStrategy":"validation","validationCode":"function assertPriority(p) { const n = Number(p); if (!(n >= -10000 && n <= 10000)) throw new Error(`priority ${p} out of range`); return n; }","typeGuard":"function isValidPriority(p: unknown): p is number { return typeof p === 'number' && p >= -10000 && p <= 10000; }","tryCatchPattern":"try { await queue.executeInQueue(...); } catch (e) { if (e.message.startsWith('Priority should be between')) { return queue.executeInQueue(handler, key, query, 0, opts); } throw e; }","preventionTips":["Clamp priorities with Math.max/Math.min before submitting","Coerce config values with Number() and check for NaN","Use named priority constants instead of raw numbers"],"tags":["validation","query-queue","priority"],"backgroundTag":"invalid-argument-value","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}