prisma/prisma · error

PSL_EXTENSION_INVALID_VALUE

PSL_EXTENSION_INVALID_VALUE

Error message

enum "${block.name}" @@type references unknown codec "${codecId}"

What it means

Emitted by the SQL family's enum entity factory when an `enum` block's `@@type` references a codec id whose native type is unknown to the target — `codecLookup.targetTypesFor(codecId)` returns `undefined`/empty. The codec is either not registered for this target or is misspelled, so the library cannot determine the column's native storage type and aborts enum construction (returns `undefined`).

Source

Thrown at packages/2-sql/9-family/src/core/authoring-entity-types.ts:33

  discriminator: 'enum',
  output: {
    factory: (
      block: PslExtensionBlock,
      ctx: AuthoringEntityContext,
    ): EnumTypeHandle | undefined => {
      const sourceId = ctx.sourceId ?? 'unknown';
      const diagnostics = ctx.diagnostics;

      const resolved = resolveEnumCodecId(block, ctx);
      if (resolved === undefined) {
        return undefined;
      }
      const { codecId, codecSpan } = resolved;

      const nativeType = ctx.codecLookup?.targetTypesFor(codecId)?.[0];
      if (nativeType === undefined) {
        diagnostics?.push({
          code: 'PSL_EXTENSION_INVALID_VALUE',
          message: `enum "${block.name}" @@type references unknown codec "${codecId}"`,
          sourceId,
          span: codecSpan,
        });
        return undefined;
      }

      const codec = ctx.codecLookup?.get(codecId);
      if (codec === undefined) {
        diagnostics?.push({
          code: 'PSL_EXTENSION_INVALID_VALUE',
          message: `enum "${block.name}" @@type codec "${codecId}" resolves in targetTypesFor but is absent from codecLookup.get`,
          sourceId,
          span: codecSpan,
        });
        return undefined;
      }

View on GitHub (pinned to 1243cdffbe)

Solutions

  1. Verify the codec id spelled in `@@type "..."` exactly matches a registered codec for the current target.
  2. Register the missing codec via the target/family's codec contribution (`AuthoringContributions` / codec registry) before authoring the enum.
  3. Ensure the target extension providing the codec is composed (see uncomposed-namespace guidance) for this family+target.
  4. If the codec was renamed in a version bump, update the `@@type` reference to the new id.

Example fix

// before
enum Status {
  ACTIVE
  INACTIVE
} @@type "statuz"   // typo / unregistered

// after
enum Status {
  ACTIVE
  INACTIVE
} @@type "status"
Defensive patterns

Strategy: validation

Validate before calling

// Validate the codec referenced by an enum's @@type exists before authoring the enum block.
function codecIsKnown(codecLookup: { targetTypesFor: (id: string) => unknown[] } | undefined, codecId: string): boolean {
  return (codecLookup?.targetTypesFor(codecId)?.length ?? 0) > 0;
}

if (!codecIsKnown(codecLookup, codecId)) {
  throw new Error(`Enum @@type references unknown codec "${codecId}". Register the codec with the target before authoring the enum.`);
}

// Also scan post-authoring diagnostics:
const unknownCodec = diagnostics.filter(
  (d) => d.code === 'PSL_EXTENSION_INVALID_VALUE' && d.message.includes('unknown codec'),
);
if (unknownCodec.length > 0) throw new Error(unknownCodec.map((d) => d.message).join('\n'));

Type guard

function isUnknownCodecDiagnostic(d: unknown): d is ContractSourceDiagnostic & { code: 'PSL_EXTENSION_INVALID_VALUE' } {
  return typeof d === 'object' && d !== null && (d as ContractSourceDiagnostic).code === 'PSL_EXTENSION_INVALID_VALUE' && /unknown codec/.test((d as ContractSourceDiagnostic).message);
}

Try / catch

// Collected diagnostic, not thrown. Validate diagnostics after enum authoring; try/catch only around emit.
try {
  emitContract(resolvedContract);
} catch (err) {
  if (unknownCodec.length > 0) throw new Error('Emit blocked: enum references unknown codec');
  throw err;
}

Prevention

When it happens

Trigger: Authoring `enum Status { ACTIVE INACTIVE } @@type "custom_codec"` where `custom_codec` is not registered in the target's codec registry. Triggered in `sqlFamilyEnumEntityDescriptor.output.factory` when `ctx.codecLookup?.targetTypesFor(codecId)?.[0]` is `undefined`.

Common situations: Typo in the `@@type` codec id. Using a codec from a target extension that is not composed for the current target. Upgrading the family/target and forgetting to register a custom codec. Authoring an enum before its codec exists.

Related errors


AI-assisted analysis of prisma/prisma@1243cdffbe (2026-08-01). Data as JSON: /data/errors/f4970627f1dac54a.json. Report an issue: GitHub.