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

Conversation

arekouzounian
Copy link
Collaborator

@arekouzounian arekouzounian commented Jun 24, 2024

WIP

Meant to address #115

  • process now propagates exit code of the command it's running
  • xhr response on frontend also holds a body field to hold error messages from bad requests (>= 400 status code)

Still working on:

  • error handling for runtime errors
  • standardized error structure

Comment on lines -108 to +110
ControllerErr: PreRunError,
RunOutput: nil,
CommandErr: nil,
ControllerErr: nil,
RunOutput: preRunOut,
CommandErr: commandErr,
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.

Comment on lines 110 to 113
cmd.Stderr.Write([]byte(err.Error()))

// 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

@@ -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.

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!

@arekouzounian
Copy link
Collaborator Author

@camerondurham I tried to implement an effective solution without modifying too much. The main idea right now is to capture the process exit code as well as the process signal, if any.

I put a bunch of comments all over to explain my thought process; it's not as standardized of an error system as it could be, but I think that it should be able to communicate what's going wrong effectively enough.

Let me know what you think; I'm also fairly sure these changes break a couple of test cases so let me know if you'd like me to change those or anything.

@arekouzounian
Copy link
Collaborator Author

forgot to add this screenshot for what it looks like with segfaults:
Screenshot 2024-06-24 at 3 44 27 PM

@camerondurham
Copy link
Owner

This looks awesome! Glad Command includes the failed output in std error response. I think the other failing integration test is just extremely flakey, but will need to take a look into that in a bit. I know you've manually verified this, so I can be okay with merging if that's still failing. But your change to include errors should not be causing anything new to fail.

I can work on fixing the flaky test later anyways.

@@ -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
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.

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 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.

@arekouzounian
Copy link
Collaborator Author

@camerondurham apologies for the delay on this. My most recent push should fix all the linter issues, I added some more debug statements, got rid of the unused error code, and am passing earthly lints locally. Let me know what else I can do 🙂

Copy link
Owner

@camerondurham camerondurham left a comment

Choose a reason for hiding this comment

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

Hey, no worries I meant to look at the other test failures.

I finally pushed a commit to fix some outdated tests after changes to pre-run commits.

Honestly the pre-run commit since it'll always be nil should probably be removed all together but I'll not block on that.

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.

@camerondurham camerondurham merged commit b24cff6 into camerondurham:main Jul 2, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants