senseyeio/roger

Improve error messages

Opened this issue · 5 comments

The status code - error message map in packet.go does not provide detailed enough error messages. Sometimes error messages are misleading, as we receive the message "Command error with status: Unknown variable/method" even when the command failed due to other reasons.

A better approach could be to query the R session and return the message of last error such that the following test passes.

func TestErrorReturn(t *testing.T) {
    con, err := NewRClient("localhost", 6311)
    if err != nil {
        t.Error("Could not connect to RServe: " + err.Error())
        return
    }

    errorText := "this is a test"
    _, err = con.Eval("stop('" + errorText + "')")

    if err == nil {
        t.Error("No error was returned")
    }

    expectedMessage := "Command error with status: " + errorText
    if err.Error() != expectedMessage {
        t.Error("Expected '" + err.Error() + "' to equal '" + expectedMessage + "'")
    }
}

This would definitely help with the client I'm building.

@harryrose, @bfallik I dig a bit into this.
So, guys, which develop Ruby binding to rserver also have the same issue.

First of all lets google:
error_catch

I think, that all is clear in this quote.

So, @harryrose, @dareid is it ok if I will implement RClient.parseAndEval and suggest pull request?

we'd still love to see this feature

Sorry for the late reply... Sounds good, @inearlydev. However, I wonder if we could improve the error message coming back from RClient.Eval rather than implementing a new ParseAndEval method?

One option is record message from R side using sink(). Send a script just after connection initiated and read the last recorded message from R when error issued.
Before any R code (can be defined in NewRClient?), eval the R code below firstly:
msg_con <- textConnection("msg_output", "w")
sink(msg_con, type="message")
sink()
when error found, Eval to get msg_output from R side.
errMsg, _ := r.Eval("msg_output")
or just last element
errMsg, _ := r.Eval("tail(msg_output, n=1")