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

propagating compiler errors #116

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions engine/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ func (ac *AsyncController) SubmitRequest(runprops *Props) *CtrlRunOutput {

if runprops.PreRunProps != nil {
preRunOut, commandErr := agent.SafeRunCmd(preRunProps)
print2.DebugPrintf("error preparing command: output=%v\n \nerror=%v", preRunOut, commandErr)
if commandErr != nil {
print2.DebugPrintf("error preparing command: output=%v\n \nerror=%v", preRunOut, commandErr)
return &CtrlRunOutput{
ControllerErr: PreRunError,
RunOutput: nil,
CommandErr: nil,
ControllerErr: nil,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is nil should probably just remove altogether.

RunOutput: preRunOut,
CommandErr: commandErr,
Comment on lines -108 to +110
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, the PreRunError was being thrown when compile commands would fail. This would make handling compilation errors different from handling runtime errors; I changed it so that both could be handled the same way.

}
}
}
Expand Down
17 changes: 16 additions & 1 deletion engine/process/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,25 @@ func main() {

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err = cmd.Run()

if err != nil {
print.ProcDebug("error running process: %v\n", err)
os.Exit(ERunningProc)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter is complaining about this, not being used, can remove lined 38 as no longer being used? ERunningProc = 20 // error code when running command

if cast, ok := err.(*exec.ExitError); ok {
if ws, ok := cast.Sys().(syscall.WaitStatus); ok {
if ws.Signaled() {
// more verbose err message
cmd.Stderr.Write([]byte(err.Error()))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns a value we may want to sanity check and debug log if it fails. It's unlikely to fail, but we can add visibility there just in case.


// signal exit code: 128 + signal code
os.Exit(128 + int(ws.Signal()))
Copy link
Collaborator Author

@arekouzounian arekouzounian Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error codes are being captured from the process command, and luckily the error from exec.Command already has a nice explanation of what caused the exit, so I just write that to the command's stderr in the case of a signal, such as a segfault

}
}

// if for some reason we can't get the wait status then we
// can just get the (probably incorrect) error code from the cast
os.Exit(cast.ExitCode())
}
}
}
2 changes: 1 addition & 1 deletion server/api/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ type RunResponse struct {
// Stderr is standard error stream from running program
Stderr string `json:"stderr"`
// Error result from either compilation or runtime errors. Will be nil if both compilation and runtime were successful.
Error error `json:"error"`
Error string `json:"error"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One big thing I noticed is that the internal json.Marshal wasn't properly marshalling the error type. If I did something like

fmt.Println("%v", err)

I would get the right error message, but once it was marshaled, it was returned as an object like

{
...
error: {Stderr: null}
}

My solution was simply to call the .Error() method on the propagated errors, to turn them into strings before they're marshaled

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to turn into string. Good catch, sorry I should've noticed that if I was writing this before.

}
5 changes: 4 additions & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func (rs RunnerServer) runHandler(w http.ResponseWriter, r *http.Request) {
output := api.RunResponse{
Stdout: RunnerOutput.Stdout,
Stderr: RunnerOutput.Stderr,
Error: RunnerOutput.CommandError,
// Error: RunnerOutput.CommandError.Error(),
}
if RunnerOutput.CommandError != nil {
output.Error = RunnerOutput.CommandError.Error()
}

err = json.NewEncoder(w).Encode(output)
Expand Down
11 changes: 6 additions & 5 deletions web-frontend/js/run-request.js
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added pre blocks for all of these, which helps with compile time errors to be shown properly:
Screenshot 2024-06-24 at 3 44 08 PM

Screenshot 2024-06-24 at 3 43 52 PM

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually looking really great! Not sure if I'll get time to review much before Wednesday, but just wanted to leave that initial feedback!

Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ function runRequest() {
reject({
status: this.status,
statusText: xhr.statusText,
body: xhr.response
});
}
};
xhr.onerror = function() {
reject({
status: this.status,
statusText: xhr.statusText,
body: xhr.response
});
};
xhr.send(JSON.stringify(req));
Expand Down Expand Up @@ -65,23 +67,22 @@ async function runCall() {
.then(function(result) {
let out = JSON.parse(result);

out["error"] = stringify(out["error"]);

stdout.innerHTML =
"Stdout: " + out["stdout"].replace(/\n/g, "<br>");
"<pre>Stdout: " + out["stdout"] + "</pre>";
stdout.removeAttribute("hidden");

stderr.innerHTML =
"Stderr: " + out["stderr"];
"<pre>Stderr: " + out["stderr"] + "</pre>";
stderr.removeAttribute("hidden");

error.innerHTML = "Error: " + out["error"];
error.innerHTML = "<pre>Error: " + out["error"] + "</pre>";
})
.catch(function(err) {
console.log(err);
stdout.setAttribute("hidden", true);
stderr.setAttribute("hidden", true);
error.innerHTML = "Error: " + stringify(err);
error.innerHTML = "<pre>Error: " + stringify(err) + "</pre>";
});
}

Expand Down
8 changes: 6 additions & 2 deletions web-frontend/style/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

.field {
background-color: #d8d8d8;
color:#282828;
color: #282828;
}
}

Expand Down Expand Up @@ -110,7 +110,11 @@ footer {
width: 90%;
}

pre {
text-wrap: balance;
}

#wrapper {
width: 50%;
margin-left: 25%;
}
}
Loading