{"record":{"id":"f91adf1aaa8be2d2","repo":"cube-js/cube","slug":"type-is-required","errorCode":null,"errorMessage":"${type} is required","messagePattern":"(.+?) is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-server-core/src/core/DevServer.ts","lineNumber":508,"sourceCode":"          [env: string]: string,\n        },\n      },\n    };\n\n    app.post('/playground/test-connection', catchErrors(\n      async (req: TestConnectionRequest, res) => {\n        const { dataSource, variables } = req.body || {};\n\n        // With multiple data sources enabled, we need to use\n        // CUBEJS_DS_<dataSource>_DB_TYPE environment variable\n        // instead of CUBEJS_DB_TYPE.\n        const type = keyByDataSource('CUBEJS_DB_TYPE', dataSource);\n\n        let driver: BaseDriver | null = null;\n\n        try {\n          if (!variables || !variables[type]) {\n            throw new Error(`${type} is required`);\n          }\n\n          // Backup env variables and set new ones in-place.\n          // We must mutate the existing process.env object (not replace it)\n          // because env-var holds a reference to the original object.\n          const backup: Record<string, string | undefined> = {};\n\n          for (const [envName, envValue] of Object.entries(variables)) {\n            backup[envName] = process.env[envName];\n            process.env[envName] = <string>envValue;\n          }\n\n          // With multiple data sources enabled, we need to put the dataSource\n          // parameter to the driver instance to read an appropriate set of\n          // driver configuration parameters. It can be undefined if multiple\n          // data source is disabled.\n          driver = CubejsServerCore.createDriver(\n            <DatabaseType>variables[type],","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-server-core/src/core/DevServer.ts#L490-L526","documentation":"The Dev Server's /playground/test-connection endpoint resolves the env variable name that must hold the database type (CUBEJS_DB_TYPE, or CUBEJS_DS_<dataSource>_DB_TYPE for multiple data sources) via keyByDataSource, then requires the submitted `variables` object to contain a value for that key. If the variables map is missing/empty or lacks that key, it throws `${type} is required` before attempting to instantiate and test the driver. Cube needs the db type to know which driver package to load and which env keys to read.","triggerScenarios":"POSTing to /playground/test-connection with a body whose `variables` is undefined, or variables lacking the key 'CUBEJS_DB_TYPE' (or 'CUBEJS_DS_<ds>_DB_TYPE' when a dataSource is passed and multiple data sources are enabled). This happens from the Developer Playground 'Test connection' UI when the database type field was not filled in.","commonSituations":"Using the Playground's connection-test form without selecting a database type; custom tooling calling the endpoint without the variables payload; multi-data-source setups where the request omits the per-data-source DB type variable; typos in the env variable key sent by the client.","solutions":["Include the database type in the request variables, e.g. { variables: { CUBEJS_DB_TYPE: 'postgres', ... } }","For multiple data sources, send the dataSource-specific key, e.g. { variables: { CUBEJS_DS_MYDS_DB_TYPE: 'mysql' } } together with dataSource in the body","Fix the client/UI to always populate the db type field before calling the endpoint","Set CUBEJS_DB_TYPE in the environment as a baseline so tooling can default to it"],"exampleFix":"// before\ncurl -X POST /playground/test-connection -d '{\"variables\":{\"CUBEJS_DB_HOST\":\"localhost\"}}'\n// after\ncurl -X POST /playground/test-connection -d '{\"variables\":{\"CUBEJS_DB_TYPE\":\"postgres\",\"CUBEJS_DB_HOST\":\"localhost\"}}'","handlingStrategy":"validation","validationCode":"async function testConnectionSafe(body) {\n  const { dataSource, variables } = body || {};\n  const type = dataSource ? `CUBEJS_DS_${dataSource.toUpperCase()}_DB_TYPE` : 'CUBEJS_DB_TYPE';\n  if (!variables || !variables[type]) {\n    throw new Error(`${type} is required by /playground/test-connection`);\n  }\n  return fetch('/playground/test-connection', { method: 'POST', body: JSON.stringify(body) });\n}","typeGuard":"function hasDbTypeVariables(v) {\n  return typeof v === 'object' && v !== null && typeof v.CUBEJS_DB_TYPE === 'string' && v.CUBEJS_DB_TYPE.length > 0;\n}","tryCatchPattern":"try {\n  const res = await fetch('/playground/test-connection', {...});\n  if (!res.ok) throw new Error((await res.json()).error);\n} catch (e) {\n  if (/DB_TYPE is required/.test(String(e))) {\n    // prompt the user to pick a database type before retrying\n  }\n}","preventionTips":["Always include CUBEJS_DB_TYPE in the variables payload sent to the test-connection endpoint","For multiple data sources, compute the per-source key CUBEJS_DS_<DS>_DB_TYPE before sending","Validate the request body client-side before posting","Default the db type from the server environment when the form field is empty"],"tags":["dev-server","playground","config","validation"],"backgroundTag":"missing-env-var","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}