Failing to create scope query
See original GitHub issueReproducing Error
For a very simple use case:
package com.some.package;
import com.a.b.c.RolloutFlag;
class SandboxHashFinder {
static final RolloutFlag FLAG_TO_DELETE = new RolloutFlag("TEST_FF_KEY");
}
There is one rule that identifies the feature flag and deletes it, then a second rule containing a query will not find a match, and so not complete.
[[rules]]
name = "delete_boolean_flag_declaration_in_class"
query = """(
(class_declaration
name: (identifier)
body: (class_body
(field_declaration
declarator: (variable_declarator
name: (identifier) @boolean_flag_constant
value: (object_creation_expression
type: (type_identifier) @constructor
arguments: (argument_list (
(string_literal) @argument
))
)
)
) @rollout_flag_declaration
)
)
(#match? @constructor "RolloutFlag$|BooleanFlag$")
(#eq? @argument "\\"@flag_key_to_delete\\"")
)"""
replace_node = "rollout_flag_declaration"
replace = ""
groups = ["delete_boolean_flag_constant"]
holes = ["flag_key_to_delete"]
[[rules]]
name = "rule_with_no_match"
query = """(
(method_invocation
object: (method_invocation
name: (_) @first_method_name
arguments: (argument_list (
(_) @first_argument
))
)
) @method_chain
(#eq? @first_argument "@boolean_flag_constant")
)"""
replace_node = "method_chain"
replace = "@lamba_function_body"
groups = []
holes = ["boolean_flag_constant"]
These rules are connected with a very simple edges.toml
file:
[[edges]]
scope = "Global"
from = "delete_boolean_flag_constant"
to = ["rule_with_no_match"]
When connected with scope=Global
or scope=Parent
, then the first rule completes successfully, and the second rule’s query has no match so does not run.
The problem is when the scope of the edge is changed to scope=Class
or scope=File
. Then the following error is raised:
thread 'main' panicked at 'Could not create scope query for "File"', src/models/scopes.rs:81:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Probable Error Source
Within scopes.rs
, my understanding is that the error is raised when the function fn get_scope_query(...)
, cannot find a node that matches the scope’s matcher in the changed node or any of the changed node’s parents. When it iterates up to the root node without finding a node that equals the scope’s match, it then executes the panic!
.
In the above case, the changed node is the feature flag declaration which does have a Class
parent node and certainly has a File
/ (program)
parent node. I’ve tried attaching a debugger to Piranha but couldn’t determine why fn get_all_matches_for_query(...)
is not able to successfully complete (due to my lack of Rust knowledge).
For context, the piranha_arguments.toml
is:
language = ["java"]
substitutions = [
["flag_key_to_delete", "TEST_FF_KEY"]
]
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top GitHub Comments
Amazing, #233 fixes it 😃 Thanks for all your help!
Closing this issue.