Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: provide more detailed error messages for browser launch errors (#…
…2157) This enhances the default stack trace and messages for browser pool launch errors to directly mention what went wrong (as some loggers may not include the `cause` property to be logged, which is quite critical for debugging what went wrong)
- Loading branch information
1 parent
c5a1b07
commit f188ebe
Showing
5 changed files
with
96 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { BrowserLaunchError, BrowserPool, PuppeteerPlugin } from '@crawlee/browser-pool'; | ||
import puppeteer from 'puppeteer'; | ||
|
||
describe('New errors in BrowserPool', () => { | ||
const pool = new BrowserPool({ | ||
browserPlugins: [new PuppeteerPlugin(puppeteer, { launchOptions: { executablePath: '/dev/null' } })], | ||
}); | ||
|
||
afterEach(() => { | ||
delete process.env.APIFY_IS_AT_HOME; | ||
}); | ||
|
||
test('they should log more information', async () => { | ||
const error = await pool.newPage().catch((err) => err); | ||
|
||
expect(error).toBeInstanceOf(BrowserLaunchError); | ||
|
||
// Must include the executable path | ||
expect(error.message).toMatch(/\/dev\/null/); | ||
// Must include the install command | ||
expect(error.message).toMatch(/npx @puppeteer\/browsers/); | ||
}); | ||
|
||
test('when running on Apify, it should also log Docker image suggestion', async () => { | ||
process.env.APIFY_IS_AT_HOME = '1'; | ||
|
||
const error = await pool.newPage().catch((err) => err); | ||
|
||
expect(error).toBeInstanceOf(BrowserLaunchError); | ||
|
||
// Must include the executable path | ||
expect(error.message).toMatch(/\/dev\/null/); | ||
// Must include the docker image suggestion | ||
expect(error.message).toMatch(/apify\/actor-node-puppeteer-chrome/); | ||
// Must include the install command | ||
expect(error.message).toMatch(/npx @puppeteer\/browsers/); | ||
}); | ||
}); |