Errors

Here are the breakdown of all the parsing errors that can happen when passing erronous arguments to the exposed functions. The parsing error ranges from passing too many arguments to the function all the way upto referencing an unknown property in the provided schema_map.

Arguments Length mismatch#

This error occurs when the number of arguments passed to the function doesnt match any of its signature. As an example lets take a look at the slice add function. It has two signatures:-

  1. (text, text)
  2. (number, number)

That means the function will not throw the argument length mismatch error as long as both the first and second arguments are either text or numbers.

// this works fine
generateFormulaASTFromArray(['add', [1, 2]]);
// so does this
generateFormulaASTFromArray(['add', ['one', 'two']]);

But if one or three arguments are passed, then the error will be thrown.

// passing too few arguments
generateFormulaASTFromArray(['add', [1]]);
// passing too many arguments
generateFormulaASTFromArray(['add', [1, 2, 3]]);

Arguments result_type mismatch#

Continuing with the above example, the function add will take on two arguments both of which has to be the type of either text or number.

Thus if a different type of argument is passed then the function would throw an error.

// passing a text constant as second argument
generateFormulaASTFromArray(['add', [1, '1']]);
// passing a checkbox symbol as first argument
generateFormulaASTFromArray(['add', [true, 1]]);

Using usupported function#

An error will also be throw when an unknown function is used. Take a look here to see the list of all the available functions.

// Using unsupported function plus
generateFormulaASTFromArray(['plus', [1, 2]]);

Unknown Property reference#

Notion formula gives the superpower of using arguments that could be another property of the schema. In that case the formula uses the value of that particular cell to formulate the final value. But if the property doesnot exist in the provided schema_map then it makes sense to throw an error, as thats also the native nature of the actual client.

We can take a look at an example of when this error will be raised using the same function add,

const schema_map = new Map([
[ 'Checkbox', { schema_id: 'checkbox', type: 'checkbox', name: 'Checkbox' } ],
[ 'Number', { schema_id: 'number', type: 'number', name: 'Number' } ]
]);
// This will throw an error as the passed schema map doesnot have a property named "Name of the property"
generateFormulaASTFromArray(['add', [{property: "Name of the property"}, 1]], schema_map);
Property arguments mismatched result_type

Property referenced arguments will be checked for argument type mismatch error.

Required schema_map argument

Even though the schema_map argument is optional, you must always provide the schema_map if you are trying to use property reference as an argument. Otherwise an error will be thrown

Typescript Power

Its highly encouraged to use typescript, since it can statically check for any of the above errors.

Last updated on