{"id":"34772a460fb608a2","repo":"typeorm/typeorm","slug":"driver-must-define-supportedisolationlevels-to-use","errorCode":null,"errorMessage":"Driver must define supportedIsolationLevels to use isolationLevel option","messagePattern":"Driver must define supportedIsolationLevels to use isolationLevel option","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"src/driver/validate-isolation-level.ts","lineNumber":18,"sourceCode":"import { TypeORMError } from \"../error/TypeORMError\"\nimport type { IsolationLevel } from \"./types/IsolationLevel\"\n\n/**\n * Validates that the given isolation level is in the provided list of supported levels.\n * Throws a TypeORMError if not supported.\n *\n * @param supported\n * @param isolationLevel\n */\nexport const validateIsolationLevel = (\n    supported: readonly IsolationLevel[],\n    isolationLevel?: IsolationLevel,\n): void => {\n    if (!isolationLevel) return\n\n    if (!supported || !Array.isArray(supported)) {\n        throw new TypeORMError(\n            `Driver must define supportedIsolationLevels to use isolationLevel option`,\n        )\n    }\n\n    if (!supported.includes(isolationLevel)) {\n        throw new TypeORMError(\n            `${isolationLevel} isolation level is not supported`,\n        )\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/driver/validate-isolation-level.ts#L1-L29","documentation":"Thrown by validateIsolationLevel when an isolationLevel is supplied but the driver's supportedIsolationLevels property is missing or not an array. The validator is called during transaction setup; it expects each driver to declare which isolation levels it supports. A missing declaration indicates a misconfigured or incomplete driver implementation.","triggerScenarios":"Passing an isolationLevel to DataSource.transaction() or queryRunner.startTransaction() while using a driver that does not define supportedIsolationLevels. Most commonly happens with a custom/third-party driver, an outdated driver version, or a driver stub that doesn't implement the full Driver interface.","commonSituations":"Using a custom or community driver that hasn't implemented supportedIsolationLevels; upgrading TypeORM and a driver adapter hasn't caught up; mocking a driver in tests without providing the array; passing an isolation level to a driver (like some older builds) that lacks the property.","solutions":["Ensure you are using a first-party, up-to-date driver that defines supportedIsolationLevels (check the driver source for the property).","If using a custom driver, add supportedIsolationLevels: [...] to the driver class listing the supported levels.","Drop the isolationLevel argument from your transaction call if the driver cannot support it."],"exampleFix":"// before — custom driver missing the property\nclass MyDriver implements Driver {\n  // supportedIsolationLevels not defined\n}\nawait dataSource.transaction(\"SERIALIZABLE\", async (em) => { ... })\n// after\nclass MyDriver implements Driver {\n  supportedIsolationLevels: IsolationLevel[] = [\"READ UNCOMMITTED\",\"READ COMMITTED\",\"REPEATABLE READ\",\"SERIALIZABLE\"]\n}","handlingStrategy":"validation","validationCode":"const supported = (dataSource.driver as any).supportedIsolationLevels\nif (!Array.isArray(supported)) {\n  throw new Error('This driver does not declare supportedIsolationLevels — cannot use isolation levels')\n}\nawait dataSource.transaction('SERIALIZABLE', async (em) => { ... })","typeGuard":"function driverSupportsIsolationLevels(driver: unknown): boolean {\n  return Array.isArray((driver as any)?.supportedIsolationLevels)\n}","tryCatchPattern":"try {\n  await dataSource.transaction('SERIALIZABLE', cb)\n} catch (e) {\n  if (e instanceof TypeORMError && /supportedIsolationLevels/.test(e.message)) {\n    await dataSource.transaction(cb) // fall back to default isolation\n  } else throw e\n}","preventionTips":["Check that dataSource.driver.supportedIsolationLevels is a non-empty array before passing an isolation level.","Keep custom drivers up to date with the Driver interface.","Avoid isolation-level arguments for drivers that don't support them."],"tags":["driver","isolation-level","transaction","missing-config"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}