Skip to content

fix: report the actual function name in the non-angle Unit error of trig functions#3673

Open
greymoth-jp wants to merge 1 commit into
josdejong:developfrom
greymoth-jp:fix/trig-unit-error-message
Open

fix: report the actual function name in the non-angle Unit error of trig functions#3673
greymoth-jp wants to merge 1 commit into
josdejong:developfrom
greymoth-jp:fix/trig-unit-error-message

Conversation

@greymoth-jp

Copy link
Copy Markdown

The shared trigUnit helper hard-codes cot in the "is no angle" error, so every function that uses it (sin, cos, tan, sec, csc, and cot) reports cot when it is given a unit that is not an angle. Five of the six name the wrong function:

math.sin(math.unit('5 celsius'))
// TypeError: Unit in function cot is no angle

That should read "function sin". The message already follows the pattern "Unit in function is no angle", so the name just needs to come from the function that was actually called instead of being hard-coded to cot. The fix reads it from self.name, which resolves to sin, cos, tan, sec, csc, or cot depending on which function the signature ends up in.

All six trig functions had an "invalid unit" test that only checked that an error was thrown, never the message, so the wrong name went unnoticed. I tightened those assertions to also check the message. The five non-cot tests fail on the current code and pass with this change; cot was already correct.

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

Successfully merging this pull request may close these issues.

1 participant