Skip to content

🐞 container.Stdout error trims stdout. #4979

Closed

Description

@itaischwartz

What is the issue?

The error string from container.Stdout sometimes trim characters from stdout.

the log below is missing ccc in Stdout

Log output

input:1: pipeline.pipeline.container.from.withExec.stdout process "sh -c echo "cccaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nddddddddddddddddddddddddddddddddddddddddddddd\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nddddddddddddddddddddddddddddddddddddddddddddd\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb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bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n
Stderr:

Please visit https://dagger.io/help#go for troubleshooting guidance.

Steps to reproduce

	d = d.Pipeline("go").Pipeline("lint")
	ctr := d.Container().
		From(fmt.Sprintf("golangci/golangci-lint:v%s-alpine", goLintVersion))
	do := `cccaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
ddddddddddddddddddddddddddddddddddddddddddddd
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
ddddddddddddddddddddddddddddddddddddddddddddd
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb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bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
`
	command := fmt.Sprintf("echo %q && exit 1", do)
	ctr = ctr.WithExec([]string{"sh", "-c", command})
	_, err := ctr.Stdout(ctx)
	fmt.Println(err)
	os.Exit(1)

SDK version

Go SDK v0.6.0

OS version

macOS

Activity

  1. changed the title [-]🐞 os.Stdout errors trim stdout prefix.[/-] [+]🐞 container.Stdout errors trim stdout.[/+] on Apr 19, 2023
  2. changed the title [-]🐞 container.Stdout errors trim stdout.[/-] [+]🐞 container.Stdout error trims stdout.[/+] on Apr 19, 2023
  3. helderco commented on Apr 19, 2023

    @helderco
    Contributor

    Thanks for the repro @itaischwartz!

    I confirm that output starts getting trimmed when stdout is greater than 2047 chars:
    https://play.dagger.cloud/playground/iz2qTdM6VtJ

  4. itaischwartz commented on Apr 19, 2023

    @itaischwartz
    Author

    probably related to

    maxExecErrorOutputBytes = 2 * 1024

    dagger/core/gateway.go

    Lines 172 to 175 in 6dac095

    // Use a circular buffer to only save the last N bytes of output, which lets
    // us prevent enormous error messages while retaining the output most likely
    // to be of interest.
    ctrOut, err := circbuf.NewBuffer(maxExecErrorOutputBytes)

    So maybe this is an "undocumented feature".
    My specific use case is that I'm trying to wrap our linter (golangci-lint).
    In case of a lint error, I want to print all the lint errors w/o trimming.

    I guess that Proposal: Replace exitCode, stdout and stderr with new patter...
    might address this use-case as well

  5. helderco commented on Apr 19, 2023

    @helderco
    Contributor

    Yes, either by fixing current stdout:

    Or doing a deprecation path with new fields:

    I want to make getting these fields via the error message obsolete.

  6. helderco commented on Apr 19, 2023

    @helderco
    Contributor

    I know you've made a workaround based on parsing that error message but you can also make sure the linter returns 0 inside the container, while getting the proper result from .Stdout() and Stderr(). Maybe you can use some other indicator to flag failure. I'm not sure if you need to capture different exit code values apart from success/failure, and if a non-empty stderr is enough for that, but any of that can be fixed with a simple shim as entrypoint.

    I may do a simple example since you're not the first one to ask. That would be better than parsing the error in my opinion.

  7. added
    area/documentation
    on May 2, 2023
  8. helderco commented on May 2, 2023

    @helderco
    Contributor
  9. helderco commented on May 12, 2023

    @helderco
    Contributor

    An update on this.

    There’s an issue to get the exit code from the error, without having to parse the message:

    And one for a combined stdout + stderr output:

    There’s also an issue to make it clearer that the output in an error is truncated:

    But we still need to find a solution to allow for full output here.

    How about adding an option in WithExec to not truncate on error:

    out, err := ctr.
        WithExec([]string{...}, dagger.ContainerWithExecOpts{
            TruncateOutputOnError: false,  // or FullOutputOnError: true
        }).
        Stdout(ctx)
    if exerr, ok := err.(*dagger.ExecError); ok {
        return exerr.Stdout  // not truncated
    }

    As suggested by @aluzzardi, we can also increase the truncate size to 100KB or something, which would be good for 99% of users without needing that flag, so it would be a quick first step.

  10. itaischwartz commented on May 17, 2023

    @itaischwartz
    Author

    @helderco I think that once we have a standard way to get Stdout, Stderr, and Exit code, we won't need any flags.
    An interface just like https://pkg.go.dev/os/exec would be a perfect fit for Dagger.
    Specifically (stderr, stdout)

    As a workaround, for now, increasing the size to 100k would be a great improvement.

  11. helderco commented on May 17, 2023

    @helderco
    Contributor

    @itaischwartz These are different things. Even after #4700 you'll still get truncated values for stdout and stderr, you just won't have to parse the error message with regex.

    We won't be able to stream to a pipe like you suggest.

  12. itaischwartz commented on May 18, 2023

    @itaischwartz
    Author

    @helderco
    My point is that I think a new interface should be introduced where stdout and stderr are not truncated by default.

    The only case where truncation makes sense is for inclusion in error messages (just like exitError stderr - see doc) .

    When I'm running a CI step, I expect the entire output from it regardless of the command exit code, as it might contain important information for debugging, such as lint errors, failed tests, stacktrace, etc.

    I'n a perfect world I'd expect something like the below example

    // dagger error for exec exitCode errors
    // Stderr and Stdout holds a subset of the standard error output
    //  if standard error was not otherwise being collected.
    
    type ExitError struct {
        Stdout []byte // truncated
        StdErr []byte // truncated
        ExitCode int
    }
    ...
    output, err := ctr.
        WithExec([]string{...}).
        CombinedOutput(ctx)
    
    // We totally failed to run the command
    if err != nil && !err.Is(err, dagger.ExitError) {
        return fmt.Errorf("command execution failed: %w", err) 
    }
    
    // print all output, just like running a regular command. Regardless if it exited successfully or not
    fmt.Println(output) // should contain non truncated stdout+stderr
    
    if exerr, ok := err.(*dagger.ExitError); ok {
        return fmt.Errorf("command failed: %w", exerr) // exerr Error() might contain truncated info and exit code
    }
    return nil
  13. self-assigned this
    on May 20, 2023
  14. helderco commented on May 22, 2023

    @helderco
    Contributor

    First of all, the truncation already happens only in err.

    My original intent was to always return the result on ExitCode, Stdout and Stderr, regardless if the command succeeded or not. But that’s not as simple as it appears.

    Returning both the result and error

    In GraphQL, when there’s an error for a specific field, that field in data would be null, and the corresponding error would be detailed in errors. They typically don’t both have meaningful values.

    Even if we override this, it could work for Go because errors are returned as values, but not in languages that raise exceptions like Python and Typescript:

    try:
        output = ctr.with_exec([...]).combined_output()
    except ExitError as e:
        # err... can't access `output`!
        ...
    print(output) # could be undefined if an error was raised

    No error → cached failure

    So what if we just don’t error and return the full result regardless of failure?

    For the resolver not to fail, we’d have to save the real exit code in a file and force exit 0 (you can do this yourself, see stop gap), otherwise buildkit returns the error.

    It’s doable but that means a failed exec will be cached. In the case of a lint or test error that’s ok, but there’s many other use cases where it’s not. You could even have an unexpected error (e.g., network issue) which you wouldn’t want to be cached. Errors can come from lots of places, it’s hard to tell.

    Granted, we can capture the error from BuildKit in the API, extract the full output from there, and return it with no error and no cached failure.

    But… then how do you know when it’s an error? You’d have to check the exit code every time:

    out, err := ctr.CombinedOutput(ctx)
    if err != nil {
        // unexpected error,
        // not from non-zero exit code
        return err
    }
    
    // need to use ExitCode to check if command failed
    exitCode, err := ctr.ExitCode(ctx)
    if err != nil {
        // another unexpected error,
        // not from non-zero exit code
    }
    
    if exitCode != 0 {
        // command failed!
    }

    That’s quite verbose to be the default.

    Flag

    So if not by default, how can you have more control over returning full output and not error?

    • Stdout / Stderr with an allowFailure option?
    • Or WithExec with allowFailure?

    In WithExec it would be better, but with the big con of having a cached failure.

    It appears it’s simpler to just control whether the error is truncated or not.

    • Stdout / Stderr with a fullOutputOnError option?
    • Or WithExec with fullOutputOnError?

    Which exec?

    If we put the flag on Stdout/Stderr remember that we can’t assume an error comes from the last command:

    out, err := ctr.
        WithExec([]string{"false"}).
        WithExec([]string{"go", "test"}).
        Stdout(ctx, dagger.ContainerStdoutOpts{
            FullOutputOnError: true,
        })

    To make sure the full output applies to the last command, we could save the digest of the last exec and compare with the one in the error and so only return full output if the error is indeed an exit error from the last exec. It’s doable (I tried!) but maybe not worth the complexity (even if an implementation detail).

    It’s much simpler to just don’t care if it’s the last exec or not, but even better is adding the flag to withExec which doesn’t have the above problem:

    out, err := ctr.
        WithExec([]string{"false"}).
        WithExec([]string{"go", "test"}, dagger.ContainerWithExecOpts{
            FullOutputOnError: true,
        }).
        Stdout(ctx)
    
    // If output in the first exec were large enough,
    // err.stdout would truncate because the failed exec
    // isn't the one with the full output option.

    However, it’s harder to control which output it applies to, without having two flags: one for stdout and another for stderr. Otherwise, you could have a huge noise output from your command in stderr, while being interested only in stdout. Or vice versa.

    Debugging with TUI/GUI

    When the use case is to use the command output for debugging purposes, we’re building better visibility tools with the new TUI (see update and interactive version demo), and a GUI you can use in your CI (Dagger Cloud).

    We’ve also started working on standardizing entrypoints with project commands (see demo from 17m12s), which makes it simpler to replace make:

    ❯ dagger do lint  # will launch TUI by default

    Still, if your use case is to have more control over the output your tool produces to the user, then you can use a stop gap.

    Stop gap

    If you need the full output and don’t mind caching the failure, you can save the exit code in a file and return 0 so you can use the full results from Stdout and Stderr without the error:

    func CommandOutput(cmd string, c *dagger.Container) (string, string, error) {
        ctr := c.
            WithExec([]string{"sh", "-c", 
                // or put this in an entrypoint script if you can
                fmt.Sprintf("%s; echo $? > /exit_code", cmd)
            })
    
        stdout, err := ctr.Stdout(ctx)
        if err != nil {
            return "", "", err
        }
    
        stderr, err := ctr.Stderr(ctx)
        if err != nil {
            return stdout, "", err
        }
    
        exitCode, err := ctr.File("exit_code").Contents(ctx)
        if err != nil {
            return stdout, stderr, err
        }
    
        if exitCode != "0" {
            return stdout, stderr, fmt.Errorf("command '%s' failed: exit code: %s", cmd, exitCode)
        }
    
        return stdout, stderr, nil
    }

    Conclusion

    I’m going to work on error types next, but I’ve submitted these quick fixes:

    If you still get truncated output with the increased limit, let us know how many bytes are being truncated (after #5163) to get a better idea.

    You can use the stop gap to get around it, but let us know whether adding the flag to not truncate on error would be helpful to avoid having to do it yourself.

    I’m not sure if it’s possible to introduce GraphQL subscriptions to stream the output from the engine to a pipe in the SDK, but that could be interesting.

    \cc @sipsma @vito @aluzzardi

  15. mircubed commented on May 23, 2023

    @mircubed
    Contributor
  16. helderco commented on May 25, 2023

    @helderco
    Contributor

    @itaischwartz fyi, this has also been released:

  17. itaischwartz commented on May 28, 2023

    @itaischwartz
    Author

    @helderco we can close this issue
    #5164 solves my problem

    Still hoping for a better way to get stdout+stderr in case of an exit error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/documentationkind/user-request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions