Name the Cause and the Offending Value
An error must say what went wrong and which value caused it. "Invalid input" sends the developer hunting; "Expected a positive integer for port, received -1" points straight at the bug. Always interpolate the offending value and the field or parameter name.
Incorrect (vague, no value, no field):
throw new Error("Invalid input");
throw new Error("Something went wrong");Correct (names the field, the expectation, and the received value):
throw new TypeError(
`Expected a positive integer for "port", received ${JSON.stringify(port)}`,
);