question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failing to create scope query

See original GitHub issue

Reproducing 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:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Pencilvesterrcommented, Sep 5, 2022

Amazing, #233 fixes it 😃 Thanks for all your help!

0reactions
ketkarameyacommented, Sep 5, 2022

Closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scope Query unable to return false (zero) instead Eloquent ...
in the query and instead the Eloquent Builder returns an object. It should return false(zero) if nothing is found.
Read more >
What is the difference between a create scope and query ...
The create scope is the one configuration in which you can create data and modify objects and is selected from the list of...
Read more >
CREATE SCOPE | Couchbase Docs
The CREATE SCOPE statement enables you to create a scope. ... Couchbase Server; Develop; Query · N1QL Language Reference; Statements; CREATE SCOPE ......
Read more >
Multiple local scope usage fails when using Builder->when()
Referencing a single scoped method (e.g. $query->isActive() ) works, but chaining breaks if it's inside a closure that's used by $query->when( ...
Read more >
Performing an Attribute Scope Query - Win32 apps
The attribute scope query is a search preference that enables a search of an object's distinguished name valued attributes to be performed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found