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

Content is printed twice #289

Closed
maliroteh opened this issue Feb 1, 2021 · 2 comments
Closed

Content is printed twice #289

maliroteh opened this issue Feb 1, 2021 · 2 comments

Comments

@maliroteh
Copy link

I have the following sample code:

const setupTasks = new Listr({
    title: 'Root Task',
    task: (ctx, task): Listr =>
        task.newListr(
            [
                {
                    options: { persistentOutput: true },
                    title: 'Sub task 1',
                    task: async (subCtx, subTask): Promise<void> => {
                        await delay(3000);
                        subTask.output = 'Output for sub task 1';
                        return Promise.resolve();
                    }
                },
                {
                    options: { persistentOutput: true },
                    title: 'Sub task 2',
                    task: async (subCtx, subTask): Promise<void> => {
                        await delay(2000);
                        subTask.output = 'Error message for sub task 2';
                        return Promise.reject();
                    }
                },
                {
                    options: { persistentOutput: true },
                    title: 'Sub task 3',
                    task: async (subCtx, subTask): Promise<void> => {
                        await delay(1000);
                        subTask.output = 'Error message for sub task 3';
                        return Promise.reject();
                    }
                }
            ],
            { concurrent: true, exitOnError: false, rendererOptions: { collapse: false, collapseErrors: false } }
        )
});

try {
    await setupTasks.run();
} catch (error) {
    console.log(error);
}

When I run this sample, I see that Listr prints the output twice as tasks progress:

Screen Shot 2021-02-01 at 3 44 39 PM

Is there a way to work around this issue to have the result printed only once?

@cenk1cenk2
Copy link
Collaborator

It seems it tries to log the error before it finishes rendering. Which it should not do because error is the last thing gets thrown out and you set exit on error to false even. That can break log-update. I will check that out.

@cenk1cenk2
Copy link
Collaborator

Okay it expects a Promise.reject with new Error() which is expected from me.

You can have a look at this example or use Promise.reject(new Error('something-something')).
https://repl.it/@CenkKl/listr2289#index.ts

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