#How to get stdout/stderr of failed command?

1 messages · Page 1 of 1 (latest)

lyric jewel
#

I have seen https://github.com/dagger/dagger/issues/5124 and know some changes to this are coming but wondering:

  1. For now what is the best way to get the stdout of a failed command and continue execution using the JS dagger SDK? Is it to just .catch() and pull err.stdout off the ExecError?
  2. Any idea on timeline for the improved API, and its unclear to me if the new API will allow for things like capturing stdout of a failed command or just let you access exitCode if that is all you care about?

This is a pretty standard pattern in CI to have a job fail and handle the error in some way so trying to figure out how to properly handle this.

Right now when running

const errorsStdout = await node()
  .withExec([
    "./node_modules/.bin/tsc",
    "-p",
    "./tsconfig.json",
    "--noEmit",
  ])
  .stdout();
console.log("this never runs");

for example the file just bails at .stdout() we never see "this never runs" and outputs this error:

14: exec docker-entrypoint.sh ./node_modules/.bin/tsc -p ./tsconfig.json --noEmit ERROR: process "docker-entrypoint.sh ./node_modules/.bin/tsc -p ./tsconfig.json --noEmit" did not complete successfully: exit code: 2

file:///Users/ianownbey/code/web/node_modules/@dagger.io/dagger/dist/api/utils.js:5
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
                                                                ^
ExecError: process "docker-entrypoint.sh ./node_modules/.bin/tsc -p ./tsconfig.json --noEmit" did not complete successfully: exit code: 2
    at file:///Users/ianownbey/code/web/node_modules/@dagger.io/dagger/dist/api/utils.js:148:27
    at Generator.throw (<anonymous>)
    at rejected (file:///Users/ianownbey/code/web/node_modules/@dagger.io/dagger/dist/api/utils.js:5:65)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: undefined,
  code: 'D109',
  cmd: [
    'docker-entrypoint.sh',
    './node_modules/.bin/tsc',
    '-p',
    './tsconfig.json',
    '--noEmit'
  ],
  exitCode: 2,
  stdout: "src/middleware.ts(15,59): error TS2322: Type 'string' is not assignable to type 'NextResponse<unknown>'.",
  stderr: ''
}
alpine island
#

Any idea on timeline for the improved API, and its unclear to me if the new API will allow for things like capturing stdout of a failed command or just let you access exitCode if that is all you care about?

Not sure yet. We're on early design stage, you can join the conversation in https://discord.com/channels/707636530424053791/1120503349599543376

#

The API will stay mostly the same though. The changes coming in Zenith are more about a framework for easily extending the API and for reducing boilerplate in most use cases. Underneath, you still use the same API you use today, just with some conveniences on top. It's possible there will be some convenience for what you're asking. You can join in that conversation and give feedback with your use case.

lyric jewel
#

ok great that is all very helpful! I really liked the { result, err } = await syntax of that, or being able to transform a chain into that type of return since some cases like CI an exec failure you want to handle, but I can add some helpers into my deal to do that no problem if this is going to be the API for awhile, and maybe is more specific to my usecase so thats where they should be anyways