Repository navigation
Description
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\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbb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bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\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
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb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bbbbbbbbbbbbbbbbbbbbbbbbbbbb
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
[-]🐞 os.Stdout errors trim stdout prefix.[/-][+]🐞 container.Stdout errors trim stdout.[/+][-]🐞 container.Stdout errors trim stdout.[/-][+]🐞 container.Stdout error trims stdout.[/+]helderco commentedon Apr 19, 2023
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
itaischwartz commentedon Apr 19, 2023
probably related to
dagger/core/gateway.go
Line 22 in 6dac095
dagger/core/gateway.go
Lines 172 to 175 in 6dac095
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,stdoutandstderrwith new patter...might address this use-case as well
helderco commentedon Apr 19, 2023
Yes, either by fixing current
stdout:Container { exitCode }doesn't work if the command fails #3192Or doing a deprecation path with new fields:
exitCode,stdoutandstderrwith new pattern #4921I want to make getting these fields via the error message obsolete.
helderco commentedon Apr 19, 2023
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()andStderr(). 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.
helderco commentedon May 2, 2023
Related:
(truncated output)to stdout/stderr errors #5077helderco commentedon May 12, 2023
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:
(truncated output)to stdout/stderr errors #5077But we still need to find a solution to allow for full output here.
How about adding an option in
WithExecto not truncate on error: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.
itaischwartz commentedon May 17, 2023
@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.
helderco commentedon May 17, 2023
@itaischwartz These are different things. Even after #4700 you'll still get truncated values for
stdoutandstderr, 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.
itaischwartz commentedon May 18, 2023
@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
helderco commentedon May 22, 2023
First of all, the truncation already happens only in
err.My original intent was to always return the result on
ExitCode,StdoutandStderr, 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
datawould benull, and the corresponding error would be detailed inerrors. 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:
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:
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/Stderrwith anallowFailureoption?WithExecwithallowFailure?In
WithExecit 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/Stderrwith afullOutputOnErroroption?WithExecwithfullOutputOnError?Which exec?
If we put the flag on
Stdout/Stderrremember that we can’t assume an error comes from the last command: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
withExecwhich doesn’t have the above problem: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: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
StdoutandStderrwithout the error: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
mircubed commentedon May 23, 2023
@itaischwartz do the these two PRs fix your issue?
helderco commentedon May 25, 2023
@itaischwartz fyi, this has also been released:
itaischwartz commentedon May 28, 2023
@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.