{"record":{"id":"23f8e28beb2a06d4","repo":"mozilla/pdf.js","slug":"invalid-pages-rotation-angle","errorCode":null,"errorMessage":"Invalid pages rotation angle.","messagePattern":"Invalid pages rotation angle\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/pdf_viewer.js","lineNumber":646,"sourceCode":"    if (!this.pdfDocument) {\n      return;\n    }\n    this.#setScale(val, { noScroll: false });\n  }\n\n  /**\n   * @type {number}\n   */\n  get pagesRotation() {\n    return this._pagesRotation;\n  }\n\n  /**\n   * @param {number} rotation - The rotation of the pages (0, 90, 180, 270).\n   */\n  set pagesRotation(rotation) {\n    if (!isValidRotation(rotation)) {\n      throw new Error(\"Invalid pages rotation angle.\");\n    }\n    if (!this.pdfDocument) {\n      return;\n    }\n    // Normalize the rotation, by clamping it to the [0, 360) range.\n    rotation %= 360;\n    if (rotation < 0) {\n      rotation += 360;\n    }\n    if (this._pagesRotation === rotation) {\n      return; // The rotation didn't change.\n    }\n    this.clearSelection();\n    this._pagesRotation = rotation;\n\n    const pageNumber = this._currentPageNumber;\n\n    this.refresh(true, { rotation });","sourceCodeStart":628,"sourceCodeEnd":664,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/web/pdf_viewer.js#L628-L664","documentation":"Thrown by PDFViewer.pagesRotation setter when rotation fails isValidRotation (must be an integer multiple of 90). Rotation is applied to all page views and must be a valid cardinal angle.","triggerScenarios":"Setting viewer.pagesRotation = 45, 90.5, NaN, or a non-number. Derived from a rotation control passing arbitrary degrees or untrusted state.","commonSituations":"Custom rotation buttons not snapping to 90-degree steps; deserialized rotation that drifted; float arithmetic producing 179.999.","solutions":["Pass only integer multiples of 90: 0, 90, 180, 270.","Snap input: rotation = Math.round(rotation / 90) * 90.","Guard with isValidRotation before assigning."],"exampleFix":"// before\nviewer.pagesRotation = degrees;\n\n// after\nif (Number.isInteger(degrees) && degrees % 90 === 0) {\n  viewer.pagesRotation = ((degrees % 360) + 360) % 360;\n}","handlingStrategy":"validation","validationCode":"if (Number.isInteger(rotation) && rotation % 90 === 0) {\n  viewer.pagesRotation = ((rotation % 360) + 360) % 360;\n}","typeGuard":"function isValidRotation(angle) {\n  return Number.isInteger(angle) && angle % 90 === 0;\n}","tryCatchPattern":null,"preventionTips":["Snap rotation to multiples of 90.","Use the shared isValidRotation helper.","Normalize rotation on deserialization."],"tags":["rotation","validation","setter","pages"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}