{"record":{"id":"64838b67b7a3f4c2","repo":"clockworklabs/SpacetimeDB","slug":"environment-name-literal-is-too-long","errorCode":null,"errorMessage":"Environment '${name}' literal is too long","messagePattern":"Environment '(.+?)' literal is too long","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/server/environment.ts","lineNumber":77,"sourceCode":"        throw new TypeError(\n          `Environment '${name}' must be a string or simple enum`\n        );\n      }\n      const values = type.value.variants.map(variant => {\n        if (\n          variant.algebraicType.tag !== 'Product' ||\n          variant.algebraicType.value.elements.length !== 0\n        ) {\n          throw new TypeError(\n            `Environment '${name}' cannot use an enum payload`\n          );\n        }\n        if (typeof variant.name !== 'string')\n          throw new TypeError(\n            `Environment '${name}' enum cases must have names`\n          );\n        if (bytes.encode(variant.name).length > MAX_ENV_VALUE_BYTES)\n          throw new TypeError(`Environment '${name}' literal is too long`);\n        return variant.name;\n      });\n      if (values.length === 0 || new Set(values).size !== values.length)\n        throw new TypeError(\n          `Environment '${name}' needs a nonempty literal union`\n        );\n      ty =\n        values.length === 1\n          ? { tag: 'StringLiteral', value: values[0]! }\n          : { tag: 'Union', value: values };\n    }\n    return { name, ty, optional };\n  });\n}\n","sourceCodeStart":59,"sourceCodeEnd":92,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/bindings-typescript/src/server/environment.ts#L59-L92","documentation":"An enum variant's name is the literal string that will appear in the environment, so its UTF-8 encoding must fit within MAX_ENV_VALUE_BYTES. Longer names would be truncated or rejected downstream, so environmentDeclarations() fails early.","triggerScenarios":"Defining an enum variant with an extremely long name (UTF-8 bytes over MAX_ENV_VALUE_BYTES) and using it as an environment variable type.","commonSituations":"Very verbose variant names like 'DeploymentModeProductionCanaryStagingOverride'; generated enums with long descriptive case names.","solutions":["Shorten the variant name below MAX_ENV_VALUE_BYTES","Rename the case to a concise token and document it","Split semantics into multiple shorter variables"],"exampleFix":"// before\nenum Mode { VeryLongDeploymentModeNameThatExceedsTheByteLimit }\n// after\nenum Mode { Prod }","handlingStrategy":"validation","validationCode":"function assertShortVariantNames(ty) {\n  const enc = new TextEncoder();\n  for (const v of ty.algebraicType.value.variants) {\n    if (enc.encode(v.name).length > MAX_ENV_VALUE_BYTES) throw new RangeError(`Variant name too long: ${v.name}`);\n  }\n}","typeGuard":"const fitsValueLimit = (name: string): boolean => new TextEncoder().encode(name).length <= MAX_ENV_VALUE_BYTES;","tryCatchPattern":null,"preventionTips":["Keep enum case names short and token-like","Check byte length (not char length) for non-ASCII names","Add a CI lint on maximum variant name length"],"tags":["environment","enum","limits","typescript"],"backgroundTag":"value-out-of-range","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-09-20T12:15:59.611Z","contentChangedAt":"2026-09-20T12:15:59.611Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}