Closed guitarvydas closed 2 years ago
Can you share a screenshot of the stack trace, and/or share the generated code so I can reproduce the error? I'm not able to reproduce it using v16.3.4. Here's what I tried:
const ohm = require('ohm-js');
const g = ohm.grammar(`G { x = "x" }`);
const s1 = g.createSemantics().addOperation('showBug', {});
s1(g.match('x')).showBug(); // Throws
const s2 = g.createSemantics().addOperation('showBug', {
_terminal: undefined
});
s2(g.match('x')).showBug(); // This throws too
I agree that throws are generated and appropriate.
The above examples helped me clarify the problem. It turns out that my code was converting one of the throws to an undefined result.
I am generating Ohm-JS code and failed to generate a "_terminal" rule.
The failing code returned "undefined" instead of a more graceful failure.
The debugger shows me:
u is "_terminal" e is undefined
return undefined
The bug is clearly my problem, but debugging could have been faster had I seen something more interesting than the generic undefined.
Should this throw instead? / error message ~~ "_terminal not defined".