Skip to content

IndexError when trying to raise JException for T0412 #42

Description

@kgutwin

This is tested against version 0.7.0 of jsonata-python, Python 3.11.15 on MacOS.

Reproduce:

import jsonata

expr = jsonata.Jsonata("$sum(x)")
expr.evaluate({"x": ["y"]})

Traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../venv/lib/python3.11/site-packages/jsonata/jsonata.py", line 2048, in evaluate
    raise err
  File ".../venv/lib/python3.11/site-packages/jsonata/jsonata.py", line 2038, in evaluate
    it = self.eval(self.ast, input, exec_env)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/jsonata/jsonata.py", line 243, in eval
    return _this._eval(expr, input, environment)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/jsonata/jsonata.py", line 291, in _eval
    result = self.evaluate_function(expr, input, environment, utils.Utils.NONE)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/jsonata/jsonata.py", line 1409, in evaluate_function
    raise err
  File ".../venv/lib/python3.11/site-packages/jsonata/jsonata.py", line 1399, in evaluate_function
    result = self.apply(proc, evaluated_args, input, environment)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/jsonata/jsonata.py", line 1422, in apply
    result = self.apply_inner(proc, args, input, environment)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/jsonata/jsonata.py", line 1454, in apply_inner
    validated_args = self.validate_arguments(proc, args, input)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/jsonata/jsonata.py", line 1601, in validate_arguments
    validated_args = signature.validate(args, context)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/jsonata/jsonata.py", line 135, in validate
    return self.signature.validate(args, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/jsonata/signature.py", line 301, in validate
    raise jexception.JException("T0412", -1, arg, param.subtype)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/jsonata/jexception.py", line 39, in __init__
    super().__init__(JException.msg(error, location, current_token, expected))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../venv/lib/python3.11/site-packages/jsonata/jexception.py", line 114, in msg
    formatted = formatted.format(arg1, arg2)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: Replacement index 2 out of range for positional args tuple

Notes:

It looks like the error message for T0412 has three arguments:

"T0412": "Argument {{index}} of Object {{token}} must be an array of {{type}}",

However, the formatter is hard coded to only handle up to two arguments. A visual scan of the error messages defined in jsonata/jexception.py suggests this might also be a problem for T2009; indeed, I can reproduce a similar error with the JSONata expression "foo" > 3.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions