{"record":{"id":"e9cbe9e58e9aa330","repo":"mozilla/pdf.js","slug":"invalid-numeric-scale","errorCode":null,"errorMessage":"Invalid numeric scale.","messagePattern":"Invalid numeric scale\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/pdf_viewer.js","lineNumber":609,"sourceCode":"      console.error(`currentPageLabel: \"${val}\" is not a valid page.`);\n    }\n  }\n\n  /**\n   * @type {number}\n   */\n  get currentScale() {\n    return this._currentScale !== UNKNOWN_SCALE\n      ? this._currentScale\n      : DEFAULT_SCALE;\n  }\n\n  /**\n   * @param {number} val - Scale of the pages in percents.\n   */\n  set currentScale(val) {\n    if (isNaN(val)) {\n      throw new Error(\"Invalid numeric scale.\");\n    }\n    if (!this.pdfDocument) {\n      return;\n    }\n    this.#setScale(val, { noScroll: false });\n  }\n\n  /**\n   * @type {string}\n   */\n  get currentScaleValue() {\n    return this._currentScaleValue;\n  }\n\n  /**\n   * @param val - The scale of the pages (in percent or predefined value).\n   */\n  set currentScaleValue(val) {","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/web/pdf_viewer.js#L591-L627","documentation":"Thrown by PDFViewer.currentScale setter when val is NaN (isNaN(val) is true). Scale must be a finite number (percent); a NaN would produce invalid zoom. Note: non-NaN invalid values (0, negative) are not caught here and are handled downstream.","triggerScenarios":"Setting viewer.currentScale = NaN, or a value that coerces to NaN (e.g. Number(undefined), Number('abc')). Common when scale is derived from a failed parse or undefined UI state.","commonSituations":"Parsing zoom input from a text field that is empty/non-numeric; scale value from a dropdown that returned undefined; division resulting in NaN.","solutions":["Validate the scale is a finite number before setting: Number.isFinite(val).","Default to a known scale (e.g. DEFAULT_SCALE) when input is missing.","Coerce and bound: const s = Math.min(MAX_SCALE, Math.max(MIN_SCALE, Number(val)))."],"exampleFix":"// before\nviewer.currentScale = Number(zoomInput.value);\n\n// after\nconst s = Number(zoomInput.value);\nif (Number.isFinite(s) && s > 0) {\n  viewer.currentScale = s;\n} else {\n  viewer.currentScaleValue = 'auto';\n}","handlingStrategy":"validation","validationCode":"const s = Number(val);\nif (Number.isFinite(s) && s > 0) {\n  viewer.currentScale = s;\n} else {\n  viewer.currentScaleValue = 'auto';\n}","typeGuard":"function isFinitePositive(v) {\n  return Number.isFinite(v) && v > 0;\n}","tryCatchPattern":null,"preventionTips":["Validate zoom input is a finite positive number.","Default to a known scale when input is empty/invalid.","Bound scale to MIN_SCALE..MAX_SCALE."],"tags":["zoom","validation","scale","setter"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}