question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'rules' of undefined

See original GitHub issue

I get this error while reading the value of the message property of a MatchFailure.

Using a debugger, my understanding is that this is caused by pexprs.Apply.prototype.toFailure being called without a grammar argument.

Indeed in my case toFailure seems called without grammar being passed to it:

pexprs.Alt.prototype.toFailure = function(grammar) {
  var fs = this.terms.map(function(t) { return t.toFailure(); });

If I do not try to read the message property, I get no crash… but no help in fixing my grammar either.

I am willing to provide my grammar and test case, should that be of any help.

Regards, Olivier.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pdubroycommented, Aug 22, 2020

Hi! There was a problem with the latest version of npm — our repo structure caused npm publish to hang. It’s finally fixed now, and I just released version 15.0.0 of Ohm.

1reaction
melloccommented, Jan 25, 2019

I’m seeing the same issue:

% node crash.js

TypeError: Cannot read property 'rules' of undefined
    at Apply.pexprs.Apply.toFailure (/home/cody/src/node-jiramark/node_modules/ohm-js/src/pexprs-toFailure.js:46:28)
    at /home/cody/src/node-jiramark/node_modules/ohm-js/src/pexprs-toFailure.js:59:50
    at Array.map (native)
    at Alt.pexprs.Alt.toFailure (/home/cody/src/node-jiramark/node_modules/ohm-js/src/pexprs-toFailure.js:59:23)
    at Not.pexprs.Not.toFailure (/home/cody/src/node-jiramark/node_modules/ohm-js/src/pexprs-toFailure.js:37:26)
    at Object.MatchState.processFailure (/home/cody/src/node-jiramark/node_modules/ohm-js/src/MatchState.js:176:31)
    at Not.pexprs.Not.eval (/home/cody/src/node-jiramark/node_modules/ohm-js/src/pexprs-eval.js:181:11)
    at Object.MatchState.eval (/home/cody/src/node-jiramark/node_modules/ohm-js/src/MatchState.js:310:20)
    at Seq.pexprs.Seq.eval (/home/cody/src/node-jiramark/node_modules/ohm-js/src/pexprs-eval.js:111:16)
    at Object.MatchState.eval (/home/cody/src/node-jiramark/node_modules/ohm-js/src/MatchState.js:310:20)

I managed to get my program down to this example:

var ohm = require('ohm-js');

var source = [
    'Crash {',
    '  Words = Word+',
    '',
    '  Word',
    '   = "[" ident+ "|" uri "]" -- link1',
    '   | ident',
    '',
    '  reserved = "{" | "}"',
    '',
    '  ident = regchar+',
    '',
    '  regchar = ~(space | reserved) any',
    '',
    '  uri = (alnum | "\u0023".."\u002F" | ":" | "_")+',
    '}'
].join('\n');

var grammar = ohm.grammar(source);

var contents = '[example|https://example.com]{'
var m = grammar.match(contents);
if (m.failed()) {
    console.log(m.shortMessage);
} else {
    console.log('Input matched grammar');
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing props to makeStyles gives error: TypeError: Cannot ...
TypeError : Cannot read property 'rules' of undefined RuleList.updateOne node_modules/jss/dist/jss.esm.js:956.
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
TypeError: Cannot read properties of undefined (reading 'id')
I have this error in my terminal: TypeError: Cannot read properties of undefined (reading 'id').
Read more >
useswr cannot read properties of undefined - You.com
To solve the "Cannot read properties of undefined" error, make sure to insert the JS script tag at the bottom of the body...
Read more >
"Cannot read property 'getData' of undefined" in Rules
When openning Manage Rules in Recruiting and selecting a template, the following error appears: "Cannot read property 'getData' of undefined".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found