{"record":{"id":"64c25f6e2db7cf78","repo":"zloirock/core-js","slug":"incorrect-lastchunkhandling-option","errorCode":null,"errorMessage":"Incorrect `lastChunkHandling` option","messagePattern":"Incorrect `lastChunkHandling` option","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/internals/uint8-from-base64.js","lineNumber":81,"sourceCode":"var writeBytes = function (bytes, elements, written) {\n  var elementsLength = elements.length;\n  for (var index = 0; index < elementsLength; index++) {\n    bytes[written + index] = elements[index];\n  }\n  return written + elementsLength;\n};\n\n/* eslint-disable max-statements, max-depth -- TODO */\nmodule.exports = function (string, options, into, maxLength) {\n  aString(string);\n  anObjectOrUndefined(options);\n  var alphabet = getAlphabetOption(options) === 'base64' ? base64Alphabet : base64UrlAlphabet;\n  var lastChunkHandling = options ? options.lastChunkHandling : undefined;\n\n  if (lastChunkHandling === undefined) lastChunkHandling = 'loose';\n\n  if (lastChunkHandling !== 'loose' && lastChunkHandling !== 'strict' && lastChunkHandling !== 'stop-before-partial') {\n    throw new TypeError('Incorrect `lastChunkHandling` option');\n  }\n\n  if (into) notDetached(into.buffer);\n\n  var stringLength = string.length;\n  var bytes = into || $Array(floor(stringLength * 3 / 4));\n  var written = 0;\n  var read = 0;\n  var chunk = '';\n  var index = 0;\n\n  if (maxLength) while (true) {\n    index = skipAsciiWhitespace(string, index);\n    if (index === stringLength) {\n      if (chunk.length > 0) {\n        if (lastChunkHandling === 'stop-before-partial') {\n          break;\n        }","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/internals/uint8-from-base64.js#L63-L99","documentation":"Uint8Array.fromBase64 (core-js polyfill) validates the lastChunkHandling option against the allowed set: 'loose' (default), 'strict', and 'stop-before-partial'. Any other value — including typos, wrong casing, or non-string values — throws this TypeError before decoding begins.","triggerScenarios":"`Uint8Array.fromBase64(s, { lastChunkHandling: 'Strict' })`, `{ lastChunkHandling: 'ignore' }`, `{ lastChunkHandling: null }` (distinct from undefined) — any value not exactly one of the three accepted strings.","commonSituations":"Copying option names from other base64 libraries, TypeScript types absent so a typo compiles, camelCase/snake_case drift ('last_chunk_handling'), or passing user-supplied config straight into the options object.","solutions":["Use exactly one of: 'loose', 'strict', 'stop-before-partial' (case-sensitive).","Remove the option entirely to get the 'loose' default.","Validate/normalize user-supplied options before passing them in.","Add a TypeScript union type: `type LastChunkHandling = 'loose' | 'strict' | 'stop-before-partial'`."],"exampleFix":"// before\nUint8Array.fromBase64(b64, { lastChunkHandling: 'Strict' }); // TypeError\n// after\nUint8Array.fromBase64(b64, { lastChunkHandling: 'strict' });","handlingStrategy":"validation","validationCode":"const VALID = ['loose', 'strict', 'stop-before-partial'];\nconst lch = options?.lastChunkHandling;\nif (lch !== undefined && !VALID.includes(lch)) {\n  throw new TypeError(`lastChunkHandling must be one of ${VALID.join(', ')}`);\n}","typeGuard":"function isLastChunkHandling(v) {\n  return v === undefined || v === 'loose' || v === 'strict' || v === 'stop-before-partial';\n}","tryCatchPattern":"try {\n  bytes = Uint8Array.fromBase64(b64, opts);\n} catch (e) {\n  if (e instanceof TypeError && /lastChunkHandling/.test(e.message)) {\n    bytes = Uint8Array.fromBase64(b64); // default 'loose'\n  } else throw e;\n}","preventionTips":["Define a TS union type for the option and let the compiler catch typos.","Never pass raw user config as the options object without validation.","Remember option values are case-sensitive lowercase strings."],"tags":["core-js","base64","options-validation","typeerror"],"backgroundTag":"invalid-option-value","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}