joshkatz / r-script

A simple little module for passing data from NodeJS to R (and back again).
MIT License
161 stars 67 forks source link

Exceptions in R code poorly handled #40

Open ccornchip opened 3 years ago

ccornchip commented 3 years ago

I'm having troubles when the R script fails with an exception. I'm getting a "SyntaxError: Unexpected end of JSON input" when my R code hits an exception.

The problem is that when I hit an R exception, body is an empty string here https://github.com/joshkatz/r-script/blob/9b87a435b3604eb96d57c53e086082f2196fa077/index.js#L39

This then causes my whole application to crash!

May I humbly suggest changing this line to

    if (body) callback(null, JSON.parse(body));