Grains fails with expected error message

All tests for Grains that expect an error fail with the message that apparently is the same as expected

Expected message: "square must be between 1 and 64"
Received value:   "square must be between 1 and 64"

What am I missing?

Don’t know how long this has been (without researching GitHub), but it is apparently due to an exercise update.

This is the code that worked two years ago that no longer works

export const square = (num) => {
  if (num < 1 || num > 64) {
    throw "square must be between 1 and 64"
  }
  return 1n << (BigInt(num) - 1n)
};

Okay, apparently the correct usage is throw new Error("square must be between 1 and 64"). There must be some subtle reason for this which I’m unfamiliar with.

The MDN docs explain this quite well. But the TL;DR; as I understand it is that things expect that the Error has message containing a string. By just throwing a string, it doesn’t have that message field.

From reading the docs it seemed to me that throw returns a string, not actually throws an error. Don’t know why throw wouldn’t throw an error by default, but not much into JavaScript these days, so I’m just gonna sign and move on… :slightly_smiling_face:

You can throw anything in JavaScript, including things like promises. It’s frowned upon but works and that’s why this particular issue is weird…