typeorm/typeorm · error · TypeORMError
Invalid shortenStrategy
Error message
Invalid shortenStrategy
What it means
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.
Source
Thrown at packages/legacy-naming-strategies/src/legacy-oracle-naming-strategy.ts:35
super()
}
columnName(
propertyName: string,
customName: string,
embeddedPrefixes: string[],
): string {
const longName: string = super.columnName(
propertyName,
customName,
embeddedPrefixes,
)
if (this.shortenStrategy === "truncate") {
return this.truncateIdentifier(longName)
} else if (this.shortenStrategy === "hash") {
return this.hashIdentifier(longName, this.DEFAULT_COLUMN_PREFIX)
} else {
throw new TypeORMError(`Invalid shortenStrategy`)
}
}
protected hashIdentifier(input: string, prefix: string): string {
if (prefix.length >= this.IDENTIFIER_MAX_SIZE) {
throw new TypeORMError(
`Prefix must be shorter than IDENTIFIER_MAX_SIZE`,
)
}
return (
prefix +
this.hash(input).substring(
0,
this.IDENTIFIER_MAX_SIZE - prefix.length,
)
)
}
View on GitHub (pinned to 04ff4daedc)
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.
Example fix
// before
new LegacyOracleNamingStrategy("shorten" as any)
// after
new LegacyOracleNamingStrategy("hash") Defensive patterns
Strategy: type-guard
Validate before calling
const SHORTEN_STRATEGIES = ['truncate', 'hash'] as const
type ShortenStrategy = typeof SHORTEN_STRATEGIES[number]
function coerceShortenStrategy(value: unknown): ShortenStrategy {
return SHORTEN_STRATEGIES.includes(value as ShortenStrategy) ? (value as ShortenStrategy) : 'hash'
} Type guard
const isShortenStrategy = (v: unknown): v is 'truncate' | 'hash' => v === 'truncate' || v === 'hash'
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Prefix must be shorter than IDENTIFIER_MAX_SIZE
- Cannot connect to database "oracledb". Please install it int
- No transforms found for version "${version}"
- To use cache you need to enable it in connection options by
- options.startupNodes required for ${this.clientType}.
AI-assisted analysis of typeorm/typeorm@04ff4daedc (2026-08-03).
Data as JSON: /data/errors/86424ad76c1070b6.json.
Report an issue: GitHub.