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

False positive quicksilver status on passthru #169

Open
marfillaster opened this issue May 6, 2020 · 10 comments
Open

False positive quicksilver status on passthru #169

marfillaster opened this issue May 6, 2020 · 10 comments

Comments

@marfillaster
Copy link

Issue Description:

The passthru usages will result in a false positive if the called command returns with non-zero exit code.

Suggested Resolution:

Check &$return_var value and raise an error to propagate the error to the calling quicksilver script.

$cmd = 'wp search-replace "://test-example.pantheonsite.io" "://example.com" --all-tables ';
passthru($cmd . ' 2>&1', $exit);
if (0 !== $exit) {
  trigger_error(sprintf('Command "%s" exit status: %s', $cmd, $exit), E_USER_ERROR);
}
@alexfornuto
Copy link

CC @sugaroverflow

@sugaroverflow
Copy link
Contributor

Hi @marfillaster thank you for opening this issue! I'm sorry, I'm not sure I understand the issue here - could you walk me through the false positive error that occurs?

My understanding of the passthru command was that we don't need to worry about the return value because we're just outputting to the browser.

@marfillaster
Copy link
Author

marfillaster commented May 14, 2020 via email

@sugaroverflow
Copy link
Contributor

Oh I see, thank you for the explanation and the examples - that's very helpful.

I'm going to go ahead and see if I can test your recommended solution with some of these examples and then we can open a PR to get these usages updated.

cc @populist who's been working on maintaining this repo with me in case you have thoughts on the passthru command updates - I'm digging into this for the first time :)

@populist
Copy link
Contributor

I definitely like the idea of providing examples that provide better error handling to folks who use them. Did a quick test of the passthru() method with our config_import script and can see errors surfaced in the output:

Fatal error: Command "drush config-import-error -y" exit status: 1 in /srv/bindings/c79d510f61594387817f1360626c86dd/code/private/scripts/drush_config_import/drush_config_import.php on line 7

@sugaroverflow
Copy link
Contributor

Thank you for looking into this and testing @populist!

I've been reading up on pass_thru() and wondering if it's being used incorrectly for these examples. Documentation indicates that pass_thru() is recommended for executing commands in which the returned output is something binary.

If we're having issues catching non-zero/non-binary exit codes, perhaps we shouldn't be using pass_thur() to begin with. If so, adding an error catch statement feels like treating the symptom, not the cause.

Instead, I'd like to replace the command with something else that supports nonzero output instead of adding a layer to the existing code - maybe with the system( ) command

Let me know what you think :)

@greg-1-anderson
Copy link
Member

passthru takes an optional second parameter to capture the status result code (0-255).

The Terminus Build Tools plugin defines a convenience wrapper for passthru:

    /**
     * Call passthru; throw an exception on failure.
     *
     * @param string $command
     */
    protected function passthru($command)
    {
        $result = 0;
        $this->log()->notice("Running {cmd}", ['cmd' => $command]);
        passthru($command, $result);

        if ($result != 0) {
            throw new TerminusException('Command `{command}` failed with exit code {status}', ['command' => $loggedCommand, 'status' => $result]);
        }
    }

I simplified it slightly for comprehensibility. We could provide some utility traits in the examples so that users who copy them verbatim would get correct behavior. It would be desirable if the examples were correct, even though it is not entirely clear whether they were intended to ever be anything more than starting points for development.

@sugaroverflow
Copy link
Contributor

I received an update from Ken that the 500 timeout error is actually a client error and that engineering is looking into it.

Thanks for the example @greg-1-anderson - I like the idea of the convenience wrapper or a utility trait that expands on passthru() and allows us to catch errors - but how do we ship that with the examples? Duplicating this in every example feels redundant. @populist and I have been looking into maintaining this repo and making it easier to use so this feels relevant.

@greg-1-anderson
Copy link
Member

I think that a good example:

  • Is clear
  • Is correct
  • Has no dependencies (works standalone)

I therefore think that duplicating a short passthru utility in every example is fine.

@greg-1-anderson
Copy link
Member

If we start having a large number of helper functions / classes in each example, though, then the "is clear" part starts to become degraded. If this happens, then we should consider the best way to introduce dependencies to reduce duplication.

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

No branches or pull requests

5 participants