#How to surface errors from `withExec()`?

1 messages · Page 1 of 1 (latest)

shell mortar
#

I'm working on a workflow that builds a container then runs a command inside the container and logs to a file on the host when something fails. The problem is, I can't figure out how to surface the actual stderr response from the container. Instead I always get the same dagger graphql error.

"UnknownDaggerError: Encountered an unknown error while requesting data via graphql\nStack: UnknownDaggerError: Encountered an unknown error while requesting data via graphql\n    at new DaggerSDKError (/src/.dagger/sdk/core.js:61780:7)\n    at new UnknownDaggerError (/src/.dagger/sdk/core.js:61820:7)\n    at <anonymous> (/src/.dagger/sdk/core.js:86274:15)\n    at processTicksAndRejections (native:7:39)"

Here is where the exec call happens: https://github.com/lifinance/contracts/pull/1260/files#diff-3e501ecd2bc35009db0d4f27cb3e9574fb959df0b68f259765a670e50852e6ecR273-R287
Here is where I try to catch the error and log it: https://github.com/lifinance/contracts/pull/1260/files#diff-3e501ecd2bc35009db0d4f27cb3e9574fb959df0b68f259765a670e50852e6ecR857-R900

north lichen
#

@shell mortar by default withExec expects the executed command to succeed (ie to terminate with a zero exit code). If the executed command fails (non-zero exit code) then withExec returns an error.

If you want to check the exit code yourself, you can change that default behavior with the expect argument to withExec. Then it will be your responsibility to handle non-zero exit codes.

shell mortar
#

@north lichen the default behavior seems sensible but just trying to figure out how to retrieve the actual message printed to stderr or even stdout when it fails...

north lichen
shell mortar
#

Ok so the last value printed to stderr should be accessible then?

north lichen
#

Yes