Skip to content

Commit

Permalink
improvement(build), log stack trace of errors thrown by build-tasks (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfirst authored Apr 15, 2024
1 parent 81211ee commit 7439e00
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scopes/pipelines/builder/build-pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class BuildPipe {
await mapSeries(this.tasksQueue, async ({ task, env }) => this.executeTask(task, env));
this.longProcessLogger.end();
const capsuleRootDir = Object.values(this.envsBuildContext)[0]?.capsuleNetwork.capsulesRootDir;
const tasksResultsList = new TaskResultsList(this.tasksQueue, this.taskResults, capsuleRootDir);
const tasksResultsList = new TaskResultsList(this.tasksQueue, this.taskResults, capsuleRootDir, this.logger);
await this.executePostBuild(tasksResultsList);

return tasksResultsList;
Expand Down
23 changes: 21 additions & 2 deletions scopes/pipelines/builder/task-results-list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chalk from 'chalk';
import { Logger } from '@teambit/logger';
import { BitError } from '@teambit/bit-error';
import { BuildTaskHelper } from './build-task';
import { TasksQueue } from './tasks-queue';
Expand All @@ -13,14 +14,17 @@ export class TaskResultsList {
*/
public tasksResults: TaskResults[],

public capsuleRootDir: string
public capsuleRootDir: string,

private logger: Logger
) {}

hasErrors(): boolean {
return this.tasksResults.some((taskResult) => taskResult.componentsResults.find((c) => c.errors?.length));
}

throwErrorsIfExist() {
this.logStackTrace();
const errorMessage = this.getErrorMessageFormatted();
if (errorMessage) {
throw new BitError(errorMessage);
Expand All @@ -30,7 +34,7 @@ export class TaskResultsList {
/**
* group errors from all tasks and show them nicely to the user
*/
public getErrorMessageFormatted(): string | null {
getErrorMessageFormatted(): string | null {
const tasksErrors: string[] = [];
let totalErrors = 0;
this.tasksResults.forEach((taskResult) => {
Expand Down Expand Up @@ -65,4 +69,19 @@ export class TaskResultsList {
const errors = rawErrors.map((e) => (typeof e === 'string' ? e : e.toString()));
return `component: ${componentResult.component.id.toString()}\n${errors.join('\n')}`;
}

private logStackTrace() {
this.tasksResults.forEach((taskResult) => {
taskResult.componentsResults.forEach((componentResult) => {
componentResult.errors?.forEach((error) => {
if (error instanceof Error) {
this.logger.error(
`failed running task ${taskResult.task.name} on ${componentResult.component.id.toString()}`,
error
);
}
});
});
});
}
}

0 comments on commit 7439e00

Please sign in to comment.