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

fix: return an error if the task fails #1669

Merged
merged 3 commits into from
Mar 10, 2020

Conversation

mitchfriedman
Copy link
Contributor

@mitchfriedman mitchfriedman commented Mar 5, 2020

What this PR does / why we need it:
This makes sure that garden doesn't return a 0 exit code if a run test fails.

In our CI, we'd like to run garden run test so that we get the streamed output from the test, instead of garden test where it suppresses the output as it executes.

If the test fails, garden needs to fail with a non-zero status code so our CI run fails as well.

Which issue(s) this PR fixes:

Fixes #1659

@mitchfriedman mitchfriedman force-pushed the error-on-failed-tasks branch from c378a4d to b41b612 Compare March 5, 2020 19:27
@mitchfriedman mitchfriedman marked this pull request as ready for review March 5, 2020 19:28
@mitchfriedman mitchfriedman force-pushed the error-on-failed-tasks branch from b41b612 to 999f802 Compare March 5, 2020 19:47
thsig
thsig previously approved these changes Mar 6, 2020
Copy link
Collaborator

@thsig thsig left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@mitchfriedman mitchfriedman force-pushed the error-on-failed-tasks branch from 999f802 to 46c4af8 Compare March 6, 2020 09:26
@mitchfriedman
Copy link
Contributor Author

In trying to get the tests to pass, I've removed changes to the task run since they do this work differently AFAICT. I have left this PR as only fixing the test run type.

Also, I had a lot of project changes, so instead I just made a new project and use that in my unit tests.

@eysi09 eysi09 dismissed thsig’s stale review March 6, 2020 09:33

I think the error handling at the command level might not be correct. Could you take a second look, @thor?

@eysi09
Copy link
Collaborator

eysi09 commented Mar 6, 2020

Whoops, wrong Thor. I was referring to @thsig.

@thsig
Copy link
Collaborator

thsig commented Mar 6, 2020

Thanks for the PR, @mitchfriedman! A few things I missed when reviewing this earlier:

  • Let's throw a RuntimeError instead of a CommandError.
    • This is for consistency with the "task-based" commands (e.g. TestCommand, DevCommand etc.) which use handleTaskResults.
  • We should handle errors the same way in each of the run commands.
    • I'd suggest writing a helper function (could e.g. be called handleActionResult) that checks result.success and returns an error similarly to how you did it here.
    • We could then end the action methods of each of the run commands with
      return handleActionResult(result)
      
      (maybe adding more parameters to the handleActionResult function as needed to generate the appropriate error message text).

@mitchfriedman
Copy link
Contributor Author

@thsig Thanks for the review and feedback.

I've addressed your feedback about using a RuntimeError instead of CommandError.

I've also added a helper function handleActionResult to allow all the action methods to have a common way to handling errors.

There were 2 issues with this:

  • I was unable to use this in the task action type since it runs the task action much differently from the rest - it uses this TaskResult task result type instead of the RunResult that the rest of the actions use. This doesn't have the success value, and instead has it's own error type built into it. I'm not very familiar with typescript and this codebase generally, so I didn't do any major refactors to change this.
  • I was unable to create tests for the service/module type since it appears the underlying shell spawn always returns a 0 exit code (perhaps because they actually behave differently i.e. fire and forget?). I'm not sure. I'll leave it to you to decide what to do here.

@mitchfriedman mitchfriedman force-pushed the error-on-failed-tasks branch from f18fac7 to f77c5f1 Compare March 7, 2020 17:51
@edvald edvald merged commit f5cf81c into garden-io:master Mar 10, 2020
@mitchfriedman mitchfriedman deleted the error-on-failed-tasks branch March 10, 2020 16:40
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.

Propagate test return value from garden run test
4 participants