Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exitOnError swallows output #295

Closed
sarink opened this issue Feb 18, 2021 · 3 comments
Closed

exitOnError swallows output #295

sarink opened this issue Feb 18, 2021 · 3 comments

Comments

@sarink
Copy link

sarink commented Feb 18, 2021

According to the docs:

// it will collect all the errors encountered if { exitOnError: false } is set as an option
// elsewise it will throw the first error encountered as expected

In practice:

  new Listr(
    [
      {
        title: 'fail',
        task: () => {
          throw new Error('fail');
        },
      },
    ],
    { exitOnError: false }
  )
    .run()
    .catch((e) => console.error('in catch', e))

If exitOnError: false is set, the catch is never triggered.

@cenk1cenk2
Copy link
Collaborator

cenk1cenk2 commented Feb 18, 2021

This is the intended behaviour, matching the original Listr and what I also prefer too. I guess there is no way unless I throw all the errors after, which is undesirable for most cases, if you set the exitOnError to false.

You can use the task.error, if you want to access the catched error, even it is exitOnError: false.

https://github.com/cenk1cenk2/listr2#throw-errors

const task = new Listr(...)
logger.fail(task.err)
// will show all of the errors that are encountered through execution

@sarink
Copy link
Author

sarink commented Feb 18, 2021

Got it, that makes sense. Thanks for your speedy response! I used task.err and everything is good :)

Perhaps the only thing to do is to update this part of the README, which shows a catch and could possibly mislead the reader into thinking that even with exitOnError: false set the errors will be re-thrown

try {
  await tasks.run()
} catch (e) {
  // it will collect all the errors encountered if { exitOnError: false } is set as an option
  // elsewise it will throw the first error encountered as expected
  console.error(e)
}

@sarink sarink closed this as completed Feb 18, 2021
@cenk1cenk2
Copy link
Collaborator

Yes, it may need an update. But I am planning to create a documentation site because README is getting much bigger than I want for node_modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants