Repository navigation
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #8469 +/- ##
=======================================
Coverage 68.06% 68.06%
=======================================
Files 621 621
Lines 99885 99886 +1
=======================================
+ Hits 67988 67991 +3
+ Misses 31897 31895 -2
|
|
Thanks for the PR! The |
|
@rgwood Maybe I'm wrong there but here is my reasoning. The problem here is the calculation of the This is because, in this precise scenario, the code entered the
In this case, the
Including,
A notable difference between the two calls ( |
|
Thanks. I'm still kind of skeptical that the category is the right thing to check here, but hopefully someone with more parser experience can weigh in. |
|
@rgwood Sure, the major problem was this condition |
| spans.len() | ||
| } else if positional_idx < signature.required_positional.len() | ||
| && spans.len() > (signature.required_positional.len() - positional_idx) | ||
| && signature.category != Category::Default |
There was a problem hiding this comment.
If we allow custom commands to change their category in the future, this might break. Is there a way we can narrow it down to where the command parsing is being impacted? or improve the logic so we test that we have enough spans ahead of time?
There was a problem hiding this comment.
@jntrnr Let us take this statement as an example if 2 < 3 { 3 }.
- This comes with this signature:
signature Signature { name: "if", usage: "", extra_usage: "", search_terms: [], required_positional: [PositionalArg { name: "cond", desc: "condition to check", shape: Expression, var_id: None, default_value: None }, PositionalArg { name: "thenOf([Block, Expression])), var_id: None, default_value: None }], rest_positional: None, vectorizes_over_list: false, named: [Flag { long: "help", short: Some('h'), arg: None, required: false, desc: "Display the help message for this command", var_id: None, default_value: None }], input_type: Any, output_type: Any, input_output_types: [(Any, Any)], allow_variants_without_examples: false, is_filter: false, creates_scope: false, allows_unknown_args: false, category: Core } - And this span array:
[Span { start: 21046, end: 21047 }, Span { start: 21048, end: 21049 }, Span { start: 21050, end: 21051 }, Span { start: 21052, end: 21057 }]
The first positional argument corresponds to 2 < 3 and so it includes 3 span elements but the second is a block { 3 } which contains just 1 span element. And this is what we should be able to know: the number of span elements corresponding to each positional argument, knowing that this can vary as a function of the input statement from the user. But I couldn’t find any function or utility that links the two, do you have an idea on the issue?
There was a problem hiding this comment.
I'm not sure if I follow what the issue is. If the issue is that the arguments number isn't being properly counted, changing the end span calculation isn't where you'd want to do the fix.
I'm mostly saying this also because that part of the parser is also pretty nasty to get right. If the fix can be done elsewhere, that'll be a lot easier to test and a lot easier to review.
|
@tcoratger have you been able to investigate another strategy maybe more robust than relying on the category? 😇 |
|
Hi @amtoine Sorry I've been very busy since, haven't had time to watch again, feel free to take this if you have time :) |
|
Thank you for giving this a try @tcoratger Will close this PR for now For those that might want to pick this up: We can not rely on the purely metadata property of the command |
Description
Issue #8385 reported a panicked problem using the
defdefine custom command and wrong uses that should not result in a panick exit anyway.Definition
def nuu [ one: list two: list three: list four: list five: list six: list ] { }Usages leading to panick output
nuu [] [] [] [] [] []nuu 0 0 0 0nuu 00 00 00 00 00Coding bug
The bug was in the
crates/nu-parser/src/parser.rsfile and more precisely in thecalculate_end_spanfunction. Part of this function was initially:And here, the
positional_idx < signature.required_positional.len() && spans.len() > (signature.required_positional.len() - positional_idx)condition is well adapted to situations likeif 2 < 3 { 3 }but in our case we should never enter thiselse ifstatement. As this is linked to theCategoryof the problem, the fix was just to add a conditional limitation there to avoid anyCategory::Defaultgoing into this condition, resulting in the following:Tests
Tests are added in the
src/tests/test_parser.rsfile to avoid this panick issue appearing again.