Closed ncordon closed 5 years ago
uast/query/xpath/xpath.go, line 44 at r1 (raw file):
As you may imagine, it's not an ideal fix, but we agreed that it makes sense for now. Can you please add a `TODO` comment to fix XPath library in the future (if we decide to support it)?
Yes, of course
uast/query/xpath/xpath.go, line 46 at r1 (raw file):
It's also worth adding the panic value to the message - it usually adds some context: ```golang fmt.Errorf("panic when executing the XPath query; wrong syntax? recovered from: %v", r) ```
I explicitly omitted that part because it only adds noise: RuntimeError: Error executing the xPath query, maybe wrong syntax? recovered from: runtime error: invalid memory address or nil pointer dereference
, but we can add it
uast/query/xpath/xpath.go, line 77 at r1 (raw file):
Yeah, sorry, also for the context, returning `smth, err2` will act as a `_, err = smth, err2; return` (assuming suggestion above). So you don't need to return `err` specifically if you define a name for it.
Thanks about the comments about the shadowing :smile: , I did not know that could such a big problem
uast/query/xpath/xpath.go, line 44 at r1 (raw file):
Yes, of course
I am going to open an issue also, because often TODO comments are just forgotten in time :trollface:
uast/query/xpath/xpath.go, line 43 at r1 (raw file):
Yeah, I totally agree. In this case, however, we need to name the error variable at least (for obvious reasons). Everything else can be `_`.
Done.
a discussion (no related file):
Also, one more thing, can we add a test case?
Added!
uast/query/xpath/xpath.go, line 43 at r1 (raw file):
Thanks, but could you please also rename the error as I mentioned in the first comment? The code is not wrong, it's just easier to break it accidentally by naming an error `err`.
Changed now!
uast/query/xpath/xpath.go, line 46 at r1 (raw file):
Maybe adding a newline will help with it? I think it may be useful to have those messages in logs, because the cause of the panic may be different next time.
Done!
uast/query/xpath/xpath.go, line 44 at r1 (raw file):
Also, please follow this format: `// TODO(ncordon): ...`
Done!
uast/query/xpath/xpath.go, line 77 at r1 (raw file):
Thanks about the comments about the shadowing :smile: , I did not know that could such a big problem
Done.
Recovers from the panic, in case it is thrown when executing the xpath query and throws an error instead. When executing, in the
python-client
after this changes, the query:the python interpreter no longer explodes and we are shown a friendlier message:
Since the modified method was already returning an error (but was not handling the panic and therefore Go killed the process of the client), this change should not carry cascade changes to the clients if they were already checking for an error when performing filter (
python-client
was catching the exception, for example).Closes #424
Signed-off-by: ncordon nacho.cordon.castillo@gmail.com
This change is