How to send errors and exceptions to the main output?

Asked

Viewed 75 times

1

I’m using Ruby 2.1 32 bits. Interpreting scripts as CGI by Apache 2. Through Local IP.

I am in a process of migrating several script in PHP to Ruby.

During the process of writing code, several times error both in typing and in some new concepts about the language and its various libraries. The problem is that every time an error or exception occurs, Apache only returns Error 500. And next, I have to open the error logs of Apache check the messages kind of confusing, which takes me useful encoding time.

My question, is there any way to send the errors and exceptions to the default output so that they are shown in the Browser and not just recognized by the server?

  • I don’t know exactly how your code is organized, nor do I have CGI experience, but it wouldn’t be easier to just run your scripts manually from the command line and check the results?

  • It would be a similar time dump to the current one. Since it would have to switch a lot between the browser and the terminal. But it was worth the option.

1 answer

2


The simplest solution is to set the overall error output as the default output at the beginning of your script:

$stderr = STDOUT

STDOUT is the object of IO representing the standard output.

  • The line above didn’t work. It actually generated some sinister error that I had to look at in the Apache log (500) and no message came from Ruby.

  • Hmm, could you show the error? I tried running a script with this setting at the top of the file and errors end up being reported in the default output.

  • [Mon Apr 27 17:20:46.925038 2015] [cgi:error] [pid 5188:tid 952] [client ::1:65332] Premature end of script headers: index.rb

  • Could you post an example of your script? It seems that the redirect has to occur after the CGI setup, according to Cob this page http://www.perlmonks.org/? node_id=262011 I don’t know much about CGI workflow, so I’m kicking some stuff in the dark; if I can see the code maybe it’ll be easier.

  • The CGI "setup" is in initialize of a class near the end of the file. The code to be threshed will probably always be above the setup code.

  • This line has to stay after setup, ideally just before your error code is executed, so it doesn’t interfere with the setup execution.

  • I had problems with my server. As soon as I can test again I come back here. I appreciate the layout.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.