]> gerrit.simantics Code Review - simantics/r.git/blob - org.simantics.r.scl/src/org/rosuda/REngine/Rserve/RserveException.java
(refs #6833) Test RExp inheritance in SCL
[simantics/r.git] / org.simantics.r.scl / src / org / rosuda / REngine / Rserve / RserveException.java
1 // JRclient library - client interface to Rserve, see http://www.rosuda.org/Rserve/
2 // Copyright (C) 2004 Simon Urbanek
3 // --- for licensing information see LICENSE file in the original JRclient distribution ---
4 //
5 //  RserveException.java
6 //
7 //  Created by Simon Urbanek on Mon Aug 18 2003.
8 //
9 //  $Id$
10 //
11
12 package org.rosuda.REngine.Rserve;
13
14 import org.rosuda.REngine.Rserve.protocol.RPacket;
15 import org.rosuda.REngine.Rserve.protocol.RTalk;
16 import org.rosuda.REngine.REngineException;
17
18 public class RserveException extends REngineException {
19     protected String err;
20     protected int reqReturnCode;
21
22     public String getRequestErrorDescription() {
23                 return getRequestErrorDescription(reqReturnCode);
24         }
25         
26     public String getRequestErrorDescription(int code) {
27         switch(code) {
28             case 0: return "no error";
29             case 2: return "R parser: input incomplete";
30             case 3: return "R parser: syntax error";
31             case RTalk.ERR_auth_failed: return "authorization failed";
32             case RTalk.ERR_conn_broken: return "connection broken";
33             case RTalk.ERR_inv_cmd: return "invalid command";
34             case RTalk.ERR_inv_par: return "invalid parameter";
35             case RTalk.ERR_IOerror: return "I/O error on the server";
36             case RTalk.ERR_not_open: return "connection is not open";
37             case RTalk.ERR_access_denied: return "access denied (local to the server)";
38             case RTalk.ERR_unsupported_cmd: return "unsupported command";
39             case RTalk.ERR_unknown_cmd: return "unknown command";
40             case RTalk.ERR_data_overflow: return "data overflow, incoming data too big";
41             case RTalk.ERR_object_too_big: return "evaluation successful, but returned object is too big to transport";
42             case RTalk.ERR_out_of_mem: return "FATAL: Rserve ran out of memory, closing connection";
43                         case RTalk.ERR_session_busy: return "session is busy";
44                         case RTalk.ERR_detach_failed: return "session detach failed";
45                 case RTalk.ERR_ctrl_closed: return "control pipe to master process is closed/broken";
46         }
47         return "error code: "+code;
48     }
49
50     public String getMessage() {
51         return super.getMessage()+((reqReturnCode!=-1)?", request status: "+getRequestErrorDescription():"");
52     }
53     
54     public RserveException(RConnection c, String msg) {
55         this(c,msg,-1);
56     }
57
58     public RserveException(RConnection c, String msg, int requestReturnCode) {
59         super(c, msg);
60         reqReturnCode=requestReturnCode;
61                 if (c!=null) c.lastError=getMessage();
62     }
63
64         public RserveException(RConnection c, String msg, RPacket p) {
65                 this(c, msg, (p==null)?-1:p.getStat());
66         }
67         
68     public int getRequestReturnCode() {
69         return reqReturnCode;
70     }
71 }