{"record":{"id":"111749ba630eebe1","repo":"cube-js/cube","slug":"query-parameter-must-be-a-non-empty-string","errorCode":null,"errorMessage":"query parameter must be a non-empty string","messagePattern":"query parameter must be a non-empty string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-api-gateway/src/gateway.ts","lineNumber":1791,"sourceCode":"      },\n      requestId: context.requestId\n    };\n  }\n\n  protected async convertQuery({ payload, context, res }: QueryConvertRequest) {\n    try {\n      await this.assertApiScope('sql', context.securityContext);\n\n      if (payload.input !== 'sql') {\n        throw new Error(`Unexpected input parameter value '${payload.input}'`);\n      }\n\n      if (payload.output !== 'rest') {\n        throw new Error(`Unexpected output parameter value '${payload.output}'`);\n      }\n\n      if (typeof payload.query !== 'string' || !payload.query.trim()) {\n        throw new Error('query parameter must be a non-empty string');\n      }\n\n      const result = await this.sqlServer.rest4sql(payload.query, context.securityContext);\n\n      await res(result);\n    } catch (e: any) {\n      this.handleError({\n        e,\n        context,\n        query: payload,\n        res,\n      });\n    }\n  }\n\n  protected async dryRun({ query, context, res }: QueryRequest) {\n    const requestStarted = new Date();\n","sourceCodeStart":1773,"sourceCodeEnd":1809,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-api-gateway/src/gateway.ts#L1773-L1809","documentation":"The /v1/convert endpoint requires `query` to be a non-empty, non-whitespace string containing the SQL to convert. convertQuery validates `typeof payload.query === 'string' && payload.query.trim()` and throws otherwise. Missing, null, numeric, or whitespace-only query values all trigger this error.","triggerScenarios":"POST /cubejs-api/v1/convert with query omitted, null, undefined, a number/object instead of a string, or a string containing only spaces/newlines.","commonSituations":"Forgetting to pass the SQL text when building the request dynamically; JSON serialization dropping an undefined query field; a UI sending the request before the SQL editor has content.","solutions":["Ensure `query` is a non-empty string containing the SQL, e.g. query: 'SELECT ...'.","Validate in the client before sending: typeof query === 'string' && query.trim().length > 0.","If the query comes from user input, trim it and refuse to submit the request until it is populated."],"exampleFix":"// before\nconst body = { input: 'sql', output: 'rest', query: sqlEditor.value ?? undefined };\n// after\nconst sql = (sqlEditor.value ?? '').trim();\nif (!sql) throw new Error('SQL is required before converting');\nconst body = { input: 'sql', output: 'rest', query: sql };","handlingStrategy":"validation","validationCode":"if (typeof body.query !== 'string' || !body.query.trim()) throw new Error('A non-empty SQL string is required for /v1/convert');","typeGuard":"function isNonEmptyString(v: unknown): v is string { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n  return await convertEndpoint(body);\n} catch (e) {\n  if (String(e?.message).includes('query parameter must be a non-empty string')) {\n    throw new Error('Provide SQL in the query field before converting');\n  }\n  throw e;\n}","preventionTips":["Guard UI submit buttons until the SQL editor has content.","Trim user-supplied SQL before sending.","Avoid passing possibly-undefined values into the body; default to empty check first."],"tags":["rest-api","parameter-validation","sql-api"],"backgroundTag":"missing-required-argument","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}