{"record":{"id":"4b455c3e861618a5","repo":"mozilla/pdf.js","slug":"invalid-rotation-must-be-a-multiple-of-90","errorCode":null,"errorMessage":"Invalid rotation: must be a multiple of 90","messagePattern":"Invalid rotation: must be a multiple of 90","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/scripting_api/field.js","lineNumber":212,"sourceCode":"    this.strokeColor = color;\n  }\n\n  get page() {\n    return this._page;\n  }\n\n  set page(_) {\n    throw new Error(\"field.page is read-only\");\n  }\n\n  get rotation() {\n    return this._rotation;\n  }\n\n  set rotation(angle) {\n    angle = Math.floor(angle);\n    if (angle % 90 !== 0) {\n      throw new Error(\"Invalid rotation: must be a multiple of 90\");\n    }\n    angle %= 360;\n    if (angle < 0) {\n      angle += 360;\n    }\n    this._rotation = angle;\n  }\n\n  get textColor() {\n    return this._textColor;\n  }\n\n  set textColor(color) {\n    if (Color._isValidColor(color)) {\n      this._textColor = color;\n    }\n  }\n","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/field.js#L194-L230","documentation":"Thrown by the setter of `Field.rotation` (src/scripting_api/field.js:212). A field's rotation must be a whole-number multiple of 90 degrees (0, 90, 180, 270) to align with the PDF coordinate system. The setter floors the value first, then rejects anything not divisible by 90.","triggerScenarios":"Assigning `f.rotation = 45`, `f.rotation = 12.5`, or a computed angle from `Math.atan2(...)` that is not quantized to 90. Passing a value in radians by mistake.","commonSituations":"Scripts that rotate a field to match a diagonal line or an image angle; reading a rotation out of an annotation whose value was never quantized; off-by-one on a UI slider that snaps to 1-degree steps.","solutions":["Quantize the angle before assigning: `f.rotation = Math.round(angle / 90) * 90`.","Ensure the source value is in degrees, not radians (`angle * 180 / Math.PI`).","Floor explicitly and assert divisibility before the call to give a clearer error."],"exampleFix":"// before\nf.rotation = degrees;\n// after\nf.rotation = Math.round(degrees / 90) * 90; // 0, 90, 180, 270","handlingStrategy":"validation","validationCode":"function setRotationSafe(field, angle) {\n  const deg = Math.round(Number(angle) / 90) * 90;\n  if (!Number.isFinite(deg)) return false;\n  field.rotation = deg;\n  return true;\n}","typeGuard":"function isQuantized90(v) {\n  const n = Math.floor(Number(v));\n  return Number.isFinite(n) && n % 90 === 0;\n}","tryCatchPattern":null,"preventionTips":["Quantize angles to 90-degree increments before assigning.","Confirm the source unit is degrees, not radians.","Floor and assert divisibility up front for a clearer error than the library's."],"tags":["scripting-api","field","validation","acrobat-js"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}