diff --git a/AUTHORS b/AUTHORS index 5ee87d1522..6c5e9274d7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -233,6 +233,5 @@ BuildTools Anik Patel <74193405+Bobingstern@users.noreply.github.com> Vrushaket Chaudhari <82214275+vrushaket@users.noreply.github.com> Praise Nnamonu <110940850+praisennamonu1@users.noreply.github.com> -vrushaket # Generated by tools/update-authors.js diff --git a/HISTORY.md b/HISTORY.md index c40767c51e..6ae6e7e91b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ - Fix #3025: improve handling of matrices and error handling in function `corr` (#3030). Thanks @vrushaket. +- Fix #3074: improve error message when using function `max` in `derivative`. # 2023-09-20, 11.11.1 diff --git a/src/function/algebra/derivative.js b/src/function/algebra/derivative.js index 503a8cf6d1..92cad23fc0 100644 --- a/src/function/algebra/derivative.js +++ b/src/function/algebra/derivative.js @@ -765,7 +765,8 @@ export const createDerivative = /* #__PURE__ */ factory(name, dependencies, ({ } node.compile().evaluate() - throw new Error('Expected TypeError, but none found') + + throw new Error('Function "' + node.name + '" is not supported by derivative, or a wrong number of arguments is passed') } /** diff --git a/test/unit-tests/function/algebra/derivative.test.js b/test/unit-tests/function/algebra/derivative.test.js index 4cfb775d4b..14c63f72f8 100644 --- a/test/unit-tests/function/algebra/derivative.test.js +++ b/test/unit-tests/function/algebra/derivative.test.js @@ -238,8 +238,12 @@ describe('derivative', function () { }) it('should throw error if expressions contain unsupported operators or functions', function () { - assert.throws(function () { derivative('x << 2', 'x') }, /Error: Operator "<<" is not supported by derivative/) - assert.throws(function () { derivative('subset(x)', 'x') }, /Error: Function "subset" is not supported by derivative/) + assert.throws(function () { derivative('x << 2', 'x') }, /Error: Operator "<<" is not supported by derivative, or a wrong number of arguments is passed/) + assert.throws(function () { derivative('subset(x)', 'x') }, /Error: Function "subset" is not supported by derivative, or a wrong number of arguments is passed/) + assert.throws(function () { derivative('max(x)', 'x') }, /Error: Function "max" is not supported by derivative, or a wrong number of arguments is passed/) + assert.throws(function () { derivative('max(x, y)', 'x') }, /Error: Function "max" is not supported by derivative, or a wrong number of arguments is passed/) + assert.throws(function () { derivative('max(x, 1)', 'x') }, /Error: Function "max" is not supported by derivative, or a wrong number of arguments is passed/) + assert.throws(function () { derivative('add(2,3,x)', 'x') }, /Error: Function "add" is not supported by derivative, or a wrong number of arguments is passed/) }) it('should have controlled behavior on arguments errors', function () {