Skip to content

Loop detector silently fails without math.js — should warn or error #45

Description

@zntznt

Problem

detectLoops (js/loops.js:52-69) calls evalFormula to probe formula signs. When math.js is not available (CLI without npm install), evalFormula returns 0 for all expressions using math.js functions (max(), min(), round(), etc.). The probe returns null (no measurable influence), the formula edge is silently dropped, and the loop table is incomplete with no error.

This is currently masked by the legacy new Function() fallback handling simple arithmetic but NOT math.js-specific functions. After #42 removes the legacy fallback, the problem extends to ALL arithmetic — even simple formulas like 10 - gold return 0 without math.js, making the loop detector silently useless in the CLI.

Fix

Add a guard at the top of detectLoops():

function detectLoops(diagram, opts = {}) {
  if (typeof math === 'undefined' || !math.compile) {
    console.warn('detectLoops: math.js not available; loop detection will be incomplete. npm install mathjs.');
  }
  // ... existing code ...
}

In the browser, math.js is always loaded so this only fires in CLI/test without npm install. The warning is actionable rather than silently producing wrong results.

Dependencies

Best applied after #42 (legacy evalFormula removal) since that makes the math.js dependency explicit.

Effort

~10 minutes. 1 file (js/loops.js). 3 lines added.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions