GithubHelp home page GithubHelp logo

Comments (4)

ethanis avatar ethanis commented on September 4, 2024 1

@luke-engle could we refactor the ProcessService#RunAndCaptureAsync method to be able to return both the text from the standard out/err streams (for example, by updating the method signature to return a tuple) and then the DockerService could use the returned value to see if the error contains a certain text?

from gh-valet.

luke-engle avatar luke-engle commented on September 4, 2024

@ethanis We may need to speed up our timeframe of when we wanted to rewrite the ProcessService in gh-valet πŸ˜“ I was looking into this and found that the error text we’re looking for (Error response from daemon: Get "https://ghcr.io/v2/": denied: denied) never actually gets captured. Well, technically it does get captured, but by the ReadStream method, which then immediately dumps it to the console and throws it away.

When the ProcessService detects a non-zero exit code:

        if (process.ExitCode != 0)
        {
            var error = await process.StandardError.ReadToEndAsync();
            throw new Exception(error);
        }

That error variable contains nothing every time, because the StandardError stream has already been consumed all the way to the end by the ReadStream method. That means there's currently no way for us to tell if someone isn't authorized or is using a token that is not permissive enough.

One way we could manage this is by maintaining a string or an array for StandardError by updating it in the ReadStream method, then if we hit an error, check if standard_error.Contains("Error response from daemon: Get "https://ghcr.io/v2/": denied: denied")? Not very performant if there happen to be a lot of errors, but I don't exactly expect that to be the case here - plus we'd only be doing this Contains check if we failed to authenticate with docker, which means output to standard error at that point should be minimal. What do you think?

(Sorry for the novel)

from gh-valet.

luke-engle avatar luke-engle commented on September 4, 2024

@ethanis That's a good point, I forgot about the RunAndCaptureAsync method! Although, I don't think we need to refactor it to return a tuple - it's already written to throw an exception with the stderr text if the process exits with a non-zero exit code. We can just try/catch and read it from the exception message. Does that sound good?

from gh-valet.

ethanis avatar ethanis commented on September 4, 2024

It sounds like a bit of a smell to use exceptions to control the flow like that. Returning a tuple and letting the caller determine what to do with an error would be a cleaner, and more easily tested, approach. We could even add in the exit code to the tuple that's being returned πŸ’­

from gh-valet.

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.