GithubHelp home page GithubHelp logo

Comments (10)

greg-1-anderson avatar greg-1-anderson commented on May 26, 2024 1

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.

from quicksilver-examples.

greg-1-anderson avatar greg-1-anderson commented on May 26, 2024 1

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.

from quicksilver-examples.

greg-1-anderson avatar greg-1-anderson commented on May 26, 2024 1

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.

from quicksilver-examples.

alexfornuto avatar alexfornuto commented on May 26, 2024

CC @sugaroverflow

from quicksilver-examples.

sugaroverflow avatar sugaroverflow commented on May 26, 2024

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.

from quicksilver-examples.

marfillaster avatar marfillaster commented on May 26, 2024

from quicksilver-examples.

sugaroverflow avatar sugaroverflow commented on May 26, 2024

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 :)

from quicksilver-examples.

populist avatar populist commented on May 26, 2024

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

from quicksilver-examples.

sugaroverflow avatar sugaroverflow commented on May 26, 2024

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 :)

from quicksilver-examples.

sugaroverflow avatar sugaroverflow commented on May 26, 2024

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.

from quicksilver-examples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.