Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error messaging #6

Open
jhoffner opened this issue Mar 28, 2014 · 0 comments
Open

Error messaging #6

jhoffner opened this issue Mar 28, 2014 · 0 comments

Comments

@jhoffner
Copy link

Currently when things such as syntax errors are thrown, a pretty confusing stack trace is returned. For example. Given the following user code:

function a(){
[stdin]:2
ESS__, output: $STDOUT};
    console._log(JSON.stringify(json));

} catch(ex){
                                                                    ^^^^^
SyntaxError: Unexpected token catch
    at Object. ([stdin]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:532:25)
    at Socket. (node.js:154:11)
    at Socket.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

I'm currently using a regexp to pull out the basic error message. So we get:
SyntaxError: Unexpected token catch

User thinks to himself: Catch? WTF? There is no catch in my code...

The problem stems from the fact that we are combining kata framework code along with the user submitted code. We need to wrap a try/catch around the user's solution so that if there are any errors, we can catch them and send them out as a JSON response.

So the above code gets turned into something along these lines:

try{
    function a(){ 

    console.log(JSON.stringify({success: true, output: []}))
}catch(ex){
  console.log(JSON.stringify({success: false, error: ex.message}))
}

This isn't an issue with the current system because there is no need to wrap the code, since the node runner uses a shovel script along with the built-in node sandbox. The shovel/shim does the wrapping for us, but it happens in a seperate file.

In the case of Ruby code, we actually pre-check the code before attempting to execute it using a Ruby parsing engine.

Ideally we can remedy this for all lanuages by using a format that is more natural to typical programming... using seperate files. In the case of JavaScript we could create a shim that does this:

try{
    var result = require './kata.js' 
    console.log(JSON.stringify(result))
}catch(ex){
  console.log(JSON.stringify({success: false, error: ex.message}))
}

The ruby version would look much the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant