{"id":"86424ad76c1070b6","repo":"typeorm/typeorm","slug":"invalid-shortenstrategy","errorCode":null,"errorMessage":"Invalid shortenStrategy","messagePattern":"Invalid shortenStrategy","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/legacy-naming-strategies/src/legacy-oracle-naming-strategy.ts","lineNumber":35,"sourceCode":"        super()\n    }\n\n    columnName(\n        propertyName: string,\n        customName: string,\n        embeddedPrefixes: string[],\n    ): string {\n        const longName: string = super.columnName(\n            propertyName,\n            customName,\n            embeddedPrefixes,\n        )\n        if (this.shortenStrategy === \"truncate\") {\n            return this.truncateIdentifier(longName)\n        } else if (this.shortenStrategy === \"hash\") {\n            return this.hashIdentifier(longName, this.DEFAULT_COLUMN_PREFIX)\n        } else {\n            throw new TypeORMError(`Invalid shortenStrategy`)\n        }\n    }\n\n    protected hashIdentifier(input: string, prefix: string): string {\n        if (prefix.length >= this.IDENTIFIER_MAX_SIZE) {\n            throw new TypeORMError(\n                `Prefix must be shorter than IDENTIFIER_MAX_SIZE`,\n            )\n        }\n        return (\n            prefix +\n            this.hash(input).substring(\n                0,\n                this.IDENTIFIER_MAX_SIZE - prefix.length,\n            )\n        )\n    }\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/packages/legacy-naming-strategies/src/legacy-oracle-naming-strategy.ts#L17-L53","documentation":"Thrown by LegacyOracleNamingStrategy.columnName when the shortenStrategy field is neither 'truncate' nor 'hash'. The constructor narrows the type to those two literals (default 'hash'), so in normal typed usage this branch is unreachable; the guard exists to defend against subclasses, casts, or JS callers that assign an invalid value.","triggerScenarios":"Constructing or configuring a LegacyOracleNamingStrategy (or subclass) with a shortenStrategy value other than 'truncate' or 'hash', then triggering columnName() during schema build/synchronize. Typically via `new LegacyOracleNamingStrategy(<badValue> as any)` or by overriding the protected field in a subclass.","commonSituations":"Custom naming-strategy subclass that sets shortenStrategy to a bespoke value; passing a config-driven string from JSON/ORM config without validation; migration from an older strategy that supported a now-removed mode.","solutions":["Set shortenStrategy to 'hash' (default, recommended for uniqueness) or 'truncate'.","If subclassing, do not override shortenStrategy with an unsupported literal.","Validate any externally-supplied strategy string against ['truncate','hash'] before constructing the strategy."],"exampleFix":"// before\nnew LegacyOracleNamingStrategy(\"shorten\" as any)\n\n// after\nnew LegacyOracleNamingStrategy(\"hash\")","handlingStrategy":"type-guard","validationCode":"const SHORTEN_STRATEGIES = ['truncate', 'hash'] as const\ntype ShortenStrategy = typeof SHORTEN_STRATEGIES[number]\nfunction coerceShortenStrategy(value: unknown): ShortenStrategy {\n  return SHORTEN_STRATEGIES.includes(value as ShortenStrategy) ? (value as ShortenStrategy) : 'hash'\n}","typeGuard":"const isShortenStrategy = (v: unknown): v is 'truncate' | 'hash' =>\n  v === 'truncate' || v === 'hash'","tryCatchPattern":null,"preventionTips":["Do not subclass LegacyOracleNamingStrategy to override shortenStrategy with a non-literal value.","When loading strategy config from external files, validate the string against the two literals before constructing."],"tags":["naming-strategy","oracle","configuration","argument-error"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}