{"record":{"id":"1e355005e6fae728","repo":"can1357/oh-my-pi","slug":"divisor-must-be-non-zero","errorCode":null,"errorMessage":"divisor must be non-zero","messagePattern":"divisor must be non-zero","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":836,"sourceCode":"\tatLeast(this: InternalType, bound: number): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"min\", bound), this[kSteps], metaOf(this));\n\t},\n\n\tatMost(this: InternalType, bound: number): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"max\", bound), this[kSteps], metaOf(this));\n\t},\n\n\tmoreThan(this: InternalType, bound: number): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"min\", bound, true), this[kSteps], metaOf(this));\n\t},\n\n\tlessThan(this: InternalType, bound: number): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"max\", bound, true), this[kSteps], metaOf(this));\n\t},\n\n\tdivisibleBy(this: InternalType, divisor: number): InternalType {\n\t\tif (this.ir.k !== \"number\") throw new OmpTypeError(`cannot apply divisibility to ${this.ir.k}`);\n\t\tif (!Number.isFinite(divisor) || divisor === 0) throw new OmpTypeError(\"divisor must be non-zero\");\n\t\treturn makeType({ ...this.ir, divisor }, this[kSteps], metaOf(this));\n\t},\n\n\tpositive(this: InternalType): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"min\", 0, true), this[kSteps], metaOf(this));\n\t},\n\n\tnegative(this: InternalType): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"max\", 0, true), this[kSteps], metaOf(this));\n\t},\n\n\tnonNegative(this: InternalType): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"min\", 0), this[kSteps], metaOf(this));\n\t},\n\n\tnonPositive(this: InternalType): InternalType {\n\t\treturn makeType(withNumericBound(this.ir, \"max\", 0), this[kSteps], metaOf(this));\n\t},","sourceCodeStart":818,"sourceCodeEnd":854,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L818-L854","documentation":"`divisibleBy` validates its divisor before installing it on the number IR. A divisor that is not a finite number or is exactly 0 makes the constraint unsatisfiable or meaningless, so omptype throws 'divisor must be non-zero' as an OmpTypeError.","triggerScenarios":"`type('number').divisibleBy(0)`, `.divisibleBy(Infinity)`, `.divisibleBy(NaN)`, or passing a divisor computed at runtime that can evaluate to 0 (e.g. from config or division by zero upstream).","commonSituations":"Divisor read from config/env defaulting to 0; arithmetic producing Infinity/NaN (x/0) passed straight into `.divisibleBy`.","solutions":["Pass a non-zero finite number: `type('number').divisibleBy(5)`.","Validate the divisor before calling: `Number.isFinite(d) && d !== 0`.","Fix the upstream computation producing 0/Infinity/NaN."],"exampleFix":"// before\nconst d = getConfig().step; // may be 0\nconst T = type('number').divisibleBy(d); // throws when d === 0\n\n// after\nif (Number.isFinite(d) && d !== 0) {\n  const T = type('number').divisibleBy(d);\n}","handlingStrategy":"validation","validationCode":"function validDivisor(d) {\n  return Number.isFinite(d) && d !== 0;\n}\nif (!validDivisor(config.step)) throw new Error('config.step must be non-zero finite');\nconst T = type('number').divisibleBy(config.step);","typeGuard":"function isUsableDivisor(d) {\n  return typeof d === 'number' && Number.isFinite(d) && d !== 0;\n}","tryCatchPattern":"try {\n  const T = type('number').divisibleBy(d);\n} catch (e) {\n  if (e instanceof OmpTypeError && e.message.includes('divisor must be non-zero')) {\n    // substitute a safe default divisor\n  } else throw e;\n}","preventionTips":["Validate config/env-sourced divisors at startup, before schema construction.","Guard upstream arithmetic that can yield 0, Infinity, or NaN.","Centralize divisor validation in one helper used by all schema builders."],"tags":["type-error","numeric-constraint","argument-validation"],"backgroundTag":"invalid-divisor-zero","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}