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 run command exit codes #1733

Merged
merged 2 commits into from
Mar 26, 2020
Merged

Fix run command exit codes #1733

merged 2 commits into from
Mar 26, 2020

Conversation

eysi09
Copy link
Collaborator

@eysi09 eysi09 commented Mar 26, 2020

What this PR does / why we need it:

The first commit fixes an issue with garden run test returning exit code 0 if the test fails and artifacts are copied.

As I was working on that, I noticed that garden run task would return the wrong exit code for local tasks, and some other inconsistencies in how the outputs were printed. The second commit addresses that.

Which issue(s) this PR fixes:

This came up in a conversation on the community Slack.

Special notes for your reviewer:

I turned the loggerType static property into a function so that commands can dynamically decide what the logger type should be. For example, commands with --interactive=true should use the basic logger.

Here are screenshots from how the outputs look now:

Screenshot 2020-03-26 at 14 41 21

Screenshot 2020-03-26 at 14 41 46

Screenshot 2020-03-26 at 14 42 17

@@ -245,7 +245,7 @@ export async function runAndCopy({
result = await runner.exec({
// Pipe the output from the command to the /tmp/output pipe, including stderr. Some shell voodoo happening
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This comment still applies 😛

Copy link
Collaborator

@edvald edvald left a comment

Choose a reason for hiding this comment

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

Mostly looks good, had a couple of questions and a comment on phrasing.

actionDescription: string
}) {
const prefix = success
? `${capitalize(actionDescription)} result:`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering about the phrasing here. "Run task result" and "Run test result" feel a little odd to me. How about using "output" instead of "result", and just using "Task" and "Test" for the action description? So it'd be simply "Task output" and "Test output". That feels more natural to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Which btw also works for the error variant, e.g. "Test failed with error".

docs/misc/faq.md Outdated

The `garden run test` command runs **a single test in interactive mode** regardless of whether or not it's cached. Interactive mode means that the output is streamed to the screen immediately and you can interact with it if applicable.

Note that due to a current limitation, Garden can't copy artifacts for tests in interactive mode. You can disable it by setting `--interactive false`. [See here](https://docs.garden.io/reference/commands#garden-run-test) for the full synopsis.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there an open issue for that? Good to link that here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No but we should add it.

}

return { result }
return handleTaskResult({ log, actionDescription: "run task", result: result! })
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be handleRunResult?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should not. This handleTaskResult function handles, as the name suggests, a result of type TaskResult, from a garden.processTasks call. The handleRunResult handles results of type RunResult, from calling something like garden.testModule.

I opted for two functions since the types, and especially return types, are different and instead enforcing correctness at the test level, should they drift

Copy link
Collaborator

Choose a reason for hiding this comment

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

Gotcha. Maybe add comments on top of the handler functions to explain the difference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point!

return "basic"
}
return "fancy"
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this preferable to stopping the logger before running the interactive part?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It felt more robust. Didn't really try the alternative.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually it seems to work just fine.

@eysi09 eysi09 force-pushed the artifacts-error branch 2 times, most recently from 9119ad4 to 2938099 Compare March 26, 2020 18:01
@eysi09 eysi09 force-pushed the artifacts-error branch 2 times, most recently from 548eada to 76563f8 Compare March 26, 2020 20:46
@eysi09 eysi09 merged commit a24b343 into master Mar 26, 2020
@eysi09 eysi09 deleted the artifacts-error branch March 26, 2020 21:58
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