Open gmbecker opened 1 year ago
@ltierney and I discussed this briefly yesterday. One idea that came up is to look for usages of tryCatch()
where a handler makes a call to grep()
or grepl()
on the error message -- this is both (1) bad practice (because of message translation) and (2) potentially a good signal of where people would benefit from a classed condition.
I suggested we could "easily" find these with a static analysis. I've written the following XPath (for searching R ASTs generated by {xmlparsedata}):
//SYMBOL_FUNCTION_CALL[text() = 'tryCatch']
/parent::expr
/following-sibling::SYMBOL_SUB
/following-sibling::expr[1][FUNCTION or OP-LAMBDA]
/expr[last()]
//SYMBOL_FUNCTION_CALL[text() = 'grep' or text() = 'grepl']
/parent::expr
/following-sibling::expr[STR_CONST]
First I ran this inside Google, consisting of internal user code and a "peculiar" snapshot of CRAN+Bioconductor (O(1K) packages). Out of 1588 files using tryCatch()
, 32 hit the above XPath. Here are some examples from CRAN:
This needs refinement:
msgid
in the base .pot files.
Endorsed by Luke
Review use of
stop()
andwarning()
to see if/where signaling structured (ie specially classed) errors would be beneficial.