Conversation
T0412 and T2009 error codes have 3 placeholders but msg() only passed 2 args to .format(), causing IndexError on replacement. Fix: make JException.msg accept *args instead of 2 fixed positional args. Updated T0412 raise to pass (index, function_name, subtype) instead of (arg, subtype). Updated T2009 raise to pass (lhs, op, rhs) instead of (lhs, rhs). Added .extra attribute to JException to store the 3rd arg. Fixes: rayokota#42
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
T2009 arguments are misordered, and exceptions using omitted formatting arguments now raise IndexError.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (3)
What changed in this PR
Fixes three-argument formatting for T0412 and T2009 exceptions.
Changes:
- Makes
JExceptionformatting variadic and stores a third argument. - Supplies three formatting values at affected call sites.
- Updates detailed exception rendering.
| File | Description |
|---|---|
src/jsonata/signature.py |
Supplies T0412 index, function, and subtype. |
src/jsonata/jsonata.py |
Supplies T2009 comparison details. |
src/jsonata/jexception.py |
Adds variadic formatting and third-argument storage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+39
to
+40
| def __init__(self, error, location=0, *args: Any): | ||
| super().__init__(JException.msg(error, location, *args)) |
| else: | ||
|
|
||
| raise jexception.JException("T2009", 0, lhs, rhs) | ||
| raise jexception.JException("T2009", 0, lhs, op, rhs) |
| # | ||
| @staticmethod | ||
| def msg(error: str, location: int, arg1: Optional[Any], arg2: Optional[Any], details: bool = False) -> str: | ||
| def msg(error: str, location: int, *args: Any, details: bool = False) -> str: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Fix
IndexError: Replacement index 2 out of range for positional args tuplewhen raising T0412 or T2009 JExceptions.Root Cause
JException.msg()had a fixed signature(error, location, arg1, arg2)but T0412 and T2009 error templates have 3 placeholders:T0412:"Argument {{index}} of Object {{token}} must be an array of {{type}}"T2009:"The values {{value}} and {{value2}} either side of operator {{token}} must be of the same data type"When
str.format(arg1, arg2)was called with these templates, Python raisedIndexErrorbecause the 3rd{}had no corresponding argument.Fix
JException.msg()to accept*args— variadic, works for 1, 2, 3, or more argssignature.pyto pass 3 args:(arg_index + 1, function_name, param.subtype)jsonata.pyto pass 3 args:(lhs, op, rhs)JException.extraattribute to store the 3rd argument (needed forget_detailed_error_message())get_detailed_error_message()now passes all 3 stored args correctlyTest
Closes #42