{"record":{"id":"1e0a856858af056e","repo":"mozilla/pdf.js","slug":"invalid-thumbnails-rotation-angle","errorCode":null,"errorMessage":"Invalid thumbnails rotation angle.","messagePattern":"Invalid thumbnails rotation angle\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/pdf_thumbnail_viewer.js","lineNumber":487,"sourceCode":"          shouldScroll = percent < 100;\n          break;\n        }\n      }\n      if (shouldScroll) {\n        thumbnailView.div.scrollIntoView(SCROLL_OPTIONS);\n      }\n    }\n\n    this._currentPageNumber = pageNumber;\n  }\n\n  get pagesRotation() {\n    return this._pagesRotation;\n  }\n\n  set pagesRotation(rotation) {\n    if (!isValidRotation(rotation)) {\n      throw new Error(\"Invalid thumbnails rotation angle.\");\n    }\n    if (!this.pdfDocument) {\n      return;\n    }\n    if (this._pagesRotation === rotation) {\n      return; // The rotation didn't change.\n    }\n    this._pagesRotation = rotation;\n\n    const updateArgs = { rotation };\n    for (const thumbnail of this._thumbnails) {\n      thumbnail.update(updateArgs);\n    }\n  }\n\n  cleanup() {\n    for (const thumbnail of this._thumbnails) {\n      if (thumbnail.renderingState !== RenderingStates.FINISHED) {","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/web/pdf_thumbnail_viewer.js#L469-L505","documentation":"Thrown by PDFThumbnailViewer.pagesRotation setter when the rotation value fails isValidRotation (must be an integer multiple of 90: 0, 90, 180, 270, ...). Thumbnails mirror the page rotation and require a valid angle.","triggerScenarios":"Setting pdfThumbnailViewer.pagesRotation = 45, or a non-integer/NaN/non-number value. Also from passing rotation derived from user input or a corrupted state without normalization.","commonSituations":"Custom toolbar rotation controls passing arbitrary degrees; deserialization of saved rotation state; passing a float like 90.0 is fine, but 45.5 or NaN throws.","solutions":["Pass only integer multiples of 90 (0, 90, 180, 270).","Normalize input before setting: rotation = Math.round(rotation / 90) * 90 % 360.","Guard with isValidRotation from ui_utils before assigning."],"exampleFix":"// before\nthumbnailViewer.pagesRotation = rawDegrees;\n\n// after\nfunction normalizeRotation(r) {\n  if (!Number.isInteger(r) || r % 90 !== 0) return null;\n  return ((r % 360) + 360) % 360;\n}\nconst rot = normalizeRotation(rawDegrees);\nif (rot !== null) thumbnailViewer.pagesRotation = rot;","handlingStrategy":"validation","validationCode":"function validRotation(r) {\n  return Number.isInteger(r) && r % 90 === 0;\n}\nif (validRotation(degrees)) {\n  thumbnailViewer.pagesRotation = degrees;\n}","typeGuard":"function isValidRotation(angle) {\n  return Number.isInteger(angle) && angle % 90 === 0;\n}","tryCatchPattern":null,"preventionTips":["Snap rotation controls to 90-degree steps.","Normalize saved rotation state on load.","Use the shared isValidRotation helper from ui_utils."],"tags":["rotation","thumbnails","validation","ui-utils"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}