{"record":{"id":"efbf27218c5d19a9","repo":"awslabs/llrt","slug":"precision-is-not-a-number","errorCode":null,"errorMessage":"Precision is not a Number","messagePattern":"Precision is not a Number","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"llrt_core/src/modules/js/@llrt/expect/jest-asymmetric-matchers.ts","lineNumber":303,"sourceCode":"    return this.inverse ? !result : result;\n  }\n\n  toString() {\n    return `String${this.inverse ? \"Not\" : \"\"}Matching`;\n  }\n\n  getExpectedType() {\n    return \"string\";\n  }\n}\n\nclass CloseTo extends AsymmetricMatcher<number> {\n  private readonly precision: number;\n\n  constructor(sample: number, precision = 2, inverse = false) {\n    if (!isA(\"Number\", sample)) throw new Error(\"Expected is not a Number\");\n\n    if (!isA(\"Number\", precision)) throw new Error(\"Precision is not a Number\");\n\n    super(sample);\n    this.inverse = inverse;\n    this.precision = precision;\n  }\n\n  asymmetricMatch(other: number) {\n    if (!isA(\"Number\", other)) return false;\n\n    let result = false;\n    if (\n      other === Number.POSITIVE_INFINITY &&\n      this.sample === Number.POSITIVE_INFINITY\n    ) {\n      result = true; // Infinity - Infinity is NaN\n    } else if (\n      other === Number.NEGATIVE_INFINITY &&\n      this.sample === Number.NEGATIVE_INFINITY","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/awslabs/llrt/blob/742fc00b82cbeaab1c1b76f0d706c302a5cbc306/llrt_core/src/modules/js/@llrt/expect/jest-asymmetric-matchers.ts#L285-L321","documentation":"CloseTo's second argument (precision, default 2) must be a number; the constructor throws this plain Error when it is not. This catches typos like passing a string digit or an options object in the precision slot.","triggerScenarios":"expect.closeTo(3.14, '2') or expect.closeTo(3.14, someNonNumber) — thrown at matcher construction.","commonSituations":"Reading precision from config/CLI where it arrives as a string, passing an options object as the second arg, or accidental extra arguments.","solutions":["Pass a number: expect.closeTo(3.14, 2).","Coerce with Number(precision) or parseInt/parseFloat if it comes from config.","Use the default precision by omitting the argument.","Fix argument order so an options object isn't passed as precision."],"exampleFix":"// before\nexpect(val).toEqual(expect.closeTo(3.14, '2'));\n// after\nexpect(val).toEqual(expect.closeTo(3.14, Number('2')));","handlingStrategy":"validation","validationCode":"if (precision !== undefined && typeof precision !== 'number') throw new TypeError('closeTo precision must be a number');","typeGuard":"const isPrecision = (p: unknown): p is number => typeof p === 'number' && Number.isInteger(p) && p >= 0;","tryCatchPattern":"try { expect(v).toEqual(expect.closeTo(n, digits)); } catch (e) { /* digits was not a number */ }","preventionTips":["Pass integer literals (0, 1, 2) for precision","Coerce config strings with parseInt","Omit precision to use the default of 2","Avoid passing options objects positionally"],"tags":["testing","validation","numbers","asymmetric-matcher"],"backgroundTag":"invalid-argument-value","analyzedSha":"742fc00b82cbeaab1c1b76f0d706c302a5cbc306","analyzedAt":"2026-09-12T11:14:07.838Z","contentChangedAt":"2026-09-12T11:14:07.838Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}