Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error messages #68

Open
fuhrmanator opened this issue Aug 16, 2024 · 0 comments
Open

Better error messages #68

fuhrmanator opened this issue Aug 16, 2024 · 0 comments

Comments

@fuhrmanator
Copy link
Owner

I'm sure we can improve error detection and messages for the parser, especially so it better integrates with @ethan-ou 's extensions.

For example, I was playing around with how the weight part of a MC question's answer is parsed. This is more user-friendly:

Weight "(weight)"
  = '%' percent:(PercentValue) '%' {
	return percent;
  }

PercentValue "(percent)"
    = percent:(!'%' .)* {
      let error = 'a value between -100 and 100'
      console.log(percent.length)
      if (percent.length == 0) expected(error + ' (did you forget to put a value?)');
      // the !'%` shows up as a 0th element in the percent array (of arrays), so we have to joing the 1th elements
	  const pct = parseFloat(percent.map(innerArray => innerArray[1]).join(""));
      console.log(pct)
      if (pct >= -100 && pct <= 100) {
        return pct;
      } else {
        expected(error)
      }
    }

The use of expected() can help a lot.

Also, we can write better tests with Jest, where an error message is expected for different cases. For now, the tests only check for valid parsing.

We could, for example, test for the proper error when a percentage value is missing:

Or is out of range:

~%150.0% here's an answer # feedback

Or is invalid:

~%blah% here's an answer # feedback
~%-17.w% here's an answer # feedback

etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant