{"record":{"id":"db2e9d4cffd17ba9","repo":"denoland/deno","slug":"err-unknown-encoding-db2e9d","errorCode":"ERR_UNKNOWN_ENCODING","errorMessage":"Unknown encoding: ${enc}","messagePattern":"Unknown encoding: (.+?)","errorType":"validation","errorClass":"ERR_UNKNOWN_ENCODING","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/string_decoder.ts","lineNumber":73,"sourceCode":"  Uint8Array,\n} = primordials;\nconst { isTypedArray } = core;\n\nconst ENCODING_UTF8 = 0;\nconst ENCODING_BASE64 = 1;\nconst ENCODING_BASE64URL = 2;\nconst ENCODING_UTF16 = 3;\nconst ENCODING_ASCII = 4;\nconst ENCODING_LATIN1 = 5;\nconst ENCODING_HEX = 6;\n\nfunction normalizeEncoding(enc) {\n  const encoding = castEncoding(enc ?? null);\n  if (!encoding) {\n    if (\n      typeof enc !== \"string\" || StringPrototypeToLowerCase(enc) !== \"raw\"\n    ) {\n      throw new ERR_UNKNOWN_ENCODING(\n        enc,\n      );\n    }\n  }\n  return String(encoding);\n}\n\nfunction isBufferType(buf) {\n  return ObjectPrototypeIsPrototypeOf(Buffer.prototype, buf) &&\n    buf.BYTES_PER_ELEMENT;\n}\n\nfunction normalizeBuffer(buf) {\n  if (!ArrayBufferIsView(buf)) {\n    throw new ERR_INVALID_ARG_TYPE(\n      \"buf\",\n      [\"Buffer\", \"TypedArray\", \"DataView\"],\n      buf,","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/string_decoder.ts#L55-L91","documentation":"StringDecoder supports a fixed set of encodings — utf8, utf16le/ucs2, latin1/binary, base64, base64url, hex, ascii. normalizeEncoding calls castEncoding on the (possibly null) name and throws ERR_UNKNOWN_ENCODING when it cannot be mapped; notably the legacy 'raw' encoding is explicitly rejected rather than aliased.","triggerScenarios":"`new StringDecoder('raw')`, `new StringDecoder('unicode')`, `new StringDecoder('utf-8x')`, or constructing with a null/undefined-ish value that fails casting and is not the exact string 'raw' (which also throws).","commonSituations":"Encoding names loaded from config/env with unsupported IANA or Windows labels ('unicode', 'cp1252'); code ported from TextDecoder which accepts far more labels (e.g. 'shift-jis'); older code relying on 'binary' spellings that were removed or on 'raw' semantics.","solutions":["Use one of the supported names: 'utf8', 'utf16le', 'latin1', 'ascii', 'base64', 'base64url', 'hex'","For any other encoding, use TextDecoder instead of StringDecoder","Normalize config values before constructing: trim, lowercase, and map aliases through a whitelist"],"exampleFix":"// before\nconst dec = new StringDecoder(process.env.ENC || 'raw');\n// ERR_UNKNOWN_ENCODING\n\n// after\nconst dec = new StringDecoder('utf8');\n// or, for wide encoding support:\nconst td = new TextDecoder('shift-jis');","handlingStrategy":"validation","validationCode":"const SUPPORTED = new Set([\n  'utf8', 'utf16le', 'latin1', 'ascii', 'base64', 'base64url', 'hex',\n]);\nconst enc = String(rawEnc ?? 'utf8').trim().toLowerCase();\nif (!SUPPORTED.has(enc)) {\n  throw new TypeError(`unsupported StringDecoder encoding: ${enc}`);\n}\nconst dec = new StringDecoder(enc);","typeGuard":"const isSupportedEncoding = (e) =>\n  ['utf8', 'utf16le', 'latin1', 'ascii', 'base64', 'base64url', 'hex'].includes(e);","tryCatchPattern":null,"preventionTips":["Whitelist encodings from config instead of forwarding raw values","Remember StringDecoder supports far fewer labels than TextDecoder","Use TextDecoder when you need encodings beyond the Node base set"],"tags":["string-decoder","encoding","node-compat"],"backgroundTag":"unknown-encoding","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}