Skip to content

Commit

Permalink
fix: throw from BasicCrawler.run on CriticalError
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin committed Jan 20, 2025
1 parent 630a8d7 commit 7594493
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/basic-crawler/src/internals/basic-crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
this.events.on(EventType.MIGRATING, boundPauseOnMigration);
this.events.on(EventType.ABORTING, boundPauseOnMigration);

let stats: FinalStatistics = {} as FinalStatistics;

try {
await this.autoscaledPool!.run();
} finally {
Expand All @@ -929,7 +931,7 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
this.events.off(EventType.ABORTING, boundPauseOnMigration);

const finalStats = this.stats.calculate();
const stats = {
stats = {
requestsFinished: this.stats.state.requestsFinished,
requestsFailed: this.stats.state.requestsFailed,
retryHistogram: this.stats.requestRetryHistogram,
Expand Down Expand Up @@ -970,10 +972,9 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
);
this.running = false;
this.hasFinishedBefore = true;

// eslint-disable-next-line no-unsafe-finally -- Return from finally is safe (it's the only `return` in the function)
return stats;
}

return stats;
}

async getRequestQueue() {
Expand Down

0 comments on commit 7594493

Please sign in to comment.