Re: [eclipse-clp-users] Error handling using socket communication

From: Joachim Schimpf <jschimpf_at_...311...>
Date: Thu, 17 Nov 2016 21:25:56 +0000
On 14/11/16 17:33, Ingo Dahn wrote:
> Hi,
> I am using Andrea Montemaggio’s php-Eclipse-connection to call Eclipse as a
> server. I want to handle Eclipse errors on the Eclipse server side, such that on
> any error
> -          The error message is bound to a specific variable of the goal called
> by the client
> -          The goal succeeds and the result, including the error message, is
> passed back to the client
> -          The socket connection is closed and Eclipse continues to listen for
> new goals in the accept_loop.
> This would be needed in particular for catching syntax errors in the goal.
> It would be great if someone could share a solution for this not-so-special problem.

Hi Ingo,

here is an example of how such a server procedure could look like.
It takes a string, tries to parse it as an ECLiPSe goal, and calls that goal.
It returns a Result (true/false/throw) and two strings containing
normal and error output.

server(String, Result, OutputString, ErrorString) :-
         open(string(""), write, Output),       % create auxiliary streams
         open(string(""), write, Error),
         set_stream(output, Output),            % redirect the standard streams
         set_stream(log_output, Output),
         set_stream(error, Error),
         set_stream(warning_output, Error),
                 term_string(Term, String),     % parse the input string
                 ( call(Term) ->                % call the goal
                     Result = true
                     Result = false
             Result = throw(Ball)
         get_stream_info(Output, name, OutputString),  %retrieve outputs
         get_stream_info(Error, name, ErrorString),
         close(output),                         % undo stream redirections

Example calls:

[eclipse 2]: server("writeln(hello)", R, O, E).
R = true
O = "hello\n"
E = ""
Yes (0.00s cpu)

[eclipse 3]: server("riteln(hello)", R, O, E).
R = throw(abort)
O = ""
E = "calling an undefined procedure riteln(hello) in module eclipse\n"
Yes (0.00s cpu)

[eclipse 4]: server("Writeln(hello)", R, O, E).
R = throw(abort)
O = ""
E = "string stream $&(stream(10)): syntax error: unexpected token\n| 
Writeln(hello)\n|        ^ here\nstring contains unexpected characters in 
term_string(_199, \"Writeln(hello)\")\n"
Yes (0.00s cpu)

I hope this answers at least part of your question.  I want to mention
two other things here:

1. It might not be a good idea to allow general goals to be sent and
called by the server, as this is a security risk.  If  you only need to
call specific goals, you should only send messages with the parameters
you need, and check and interpret these messages in your server explicitly.

2. Instead of sending a string in ECLiPSe-syntax, you might consider using
EXDR-format, which is an efficient encoding of a large subset of valid
ECLiPSe terms.  It is generally easier to create from other programming
languages, in particular as it avoids all the tedious problems with quoting.
The Tcl and Java interfaces can both read/write this format.  See

Received on Thu Nov 17 2016 - 21:26:05 CET

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:30 CEST