{"record":{"id":"481e46454f97f398","repo":"Budibase/budibase","slug":"err-message-481e46","errorCode":null,"errorMessage":"${err.message}","messagePattern":"\\$\\{err\\.message\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/integrations/microsoftSqlServer.ts","lineNumber":390,"sourceCode":"        }\n      }\n      // this is a hack to get the inserted ID back,\n      //  no way to do this with Knex nicely\n      const sql =\n        operation === Operation.CREATE\n          ? `${query.sql}; SELECT SCOPE_IDENTITY() AS id;`\n          : query.sql\n      this.log(sql, query.bindings)\n      return await request.query(sql)\n    } catch (err: any) {\n      let readableMessage = getReadableErrorMessage(\n        SourceName.SQL_SERVER,\n        err.number\n      )\n      if (readableMessage) {\n        throw new Error(readableMessage, { cause: err })\n      } else {\n        throw new Error(err.message as string, { cause: err })\n      }\n    }\n  }\n\n  getDefinitionSQL(tableName: string, schemaName: string): SqlQuery {\n    return {\n      sql: `select *\n            from INFORMATION_SCHEMA.COLUMNS\n            where TABLE_NAME=@p0 AND TABLE_SCHEMA=@p1`,\n      bindings: [tableName, schemaName],\n    }\n  }\n\n  getConstraintsSQL(tableName: string, schemaName: string): SqlQuery {\n    return {\n      sql: `SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS TC\n            INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KU\n              ON TC.CONSTRAINT_TYPE = 'PRIMARY KEY' ","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/integrations/microsoftSqlServer.ts#L372-L408","documentation":"internalQuery() runs SQL against SQL Server and first tries getReadableErrorMessage(SourceName.SQL_SERVER, err.number). If the driver error's number is not in the mapping (readableMessage is falsy), the integration rethrows the raw driver message via new Error(err.message, { cause: err }), preserving the original error as cause.","triggerScenarios":"Any SQL Server execution error whose err.number has no entry in the readable-error mapping — uncommon SQL Server codes, timeouts, deadlocks, connection drops mid-query, or driver-level errors where err.number is undefined.","commonSituations":"Query timeouts on long-running statements; deadlock victims; connection reset while streaming results; newly encountered SQL Server error codes not yet mapped in Budibase's readable-error table.","solutions":["Inspect error.cause (the original driver error) for the real SQL Server error number and details","Fix the underlying SQL/data issue indicated by the raw message","Increase the request timeout for long-running queries","If the code deserves a friendly message, add it to the SQL_SERVER readable-error mapping"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// no pre-call validation exists for unmapped errors; bound execution time instead\nconst query = { sql: \"SELECT ...\", timeout: 30000 }","typeGuard":"function isUnmappedDriverError(err: unknown): err is { message: string; cause?: unknown } {\n  return err instanceof Error && typeof (err as any).number !== \"number\"\n}","tryCatchPattern":"try {\n  return await ds.query(sqlQuery)\n} catch (err) {\n  // raw driver message; original error chained as cause\n  const original = (err as any).cause\n  if (original?.code === \"ETIMEOUT\" || /timeout/i.test(err.message)) {\n    // retry with a longer timeout\n  }\n  throw err\n}","preventionTips":["Set sane request timeouts for long-running statements","Log err.cause to capture the real SQL Server error number for diagnosis","Retry deadlock/timeout errors with backoff where idempotent","Contribute unmapped common error numbers to the readable-error mapping"],"tags":["sql-server","query","unmapped-error","driver-error"],"backgroundTag":"sql-query-error","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}