jscodeshift icon indicating copy to clipboard operation
jscodeshift copied to clipboard

Better error message when trying to replace CallExpressions instead of ExpressionStatement or VariableDeclarator

Open Daniel15 opened this issue 8 years ago • 2 comments

I hit a vague "Could not replace path" error today: http://astexplorer.net/#/gist/cfb2f93a39c4a80a1ecf44930092b59f/edca9a554a9aad19c62f098b07ee024a9c418241

After digging around for a while, I found #157, where @fkling wrote:

You should not be looking for CallExpressions but for ExpressionStatements that contain a CallExpression that matches your constraints.

This was exactly my issue! Changing the script to instead look for the ExpressionStatement worked fine: http://astexplorer.net/#/gist/cfb2f93a39c4a80a1ecf44930092b59f/7b4a6f22da67d31cb18e768e0da975f26244ea1e

Can we make the "Could not replace path" error better?

Daniel15 avatar Jul 31 '17 19:07 Daniel15

In my case I actually needed to replace a VariableDeclarator not an ExpressionStatement, but it's mostly the same.

Daniel15 avatar Jul 31 '17 19:07 Daniel15

what is the best place to improve this error message?

sibelius avatar Jul 01 '20 14:07 sibelius