Skip to content

Conversation

@mxschmitt
Copy link
Contributor

@mxschmitt mxschmitt commented Apr 18, 2025

Minimal repro:

const { test, expect } = require('@playwright/test');
test('one', async ({ page }) => {
  await page.evaluate(() => {
    throw new Error('error');
  });
});

Stack:

    Error: ENOENT: no such file or directory, open 'eval at evaluate (:313:29), <anonymous>'
        at open (node:internal/fs/promises:638:25)
        at Object.readFile (node:internal/fs/promises:1242:14)
        at loadSource (/Users/maxschmitt/Developer/playwright/packages/playwright/src/errorContext.ts:146:14)
        at attachErrorContext (/Users/maxschmitt/Developer/playwright/packages/playwright/src/errorContext.ts:95:20)
        at ArtifactsRecorder.didFinishTest (/Users/maxschmitt/Developer/playwright/packages/playwright/src/index.ts:725:7)
        at Object.playwrightFixtures._setupArtifacts.auto [as fn] (/Users/maxschmitt/Developer/playwright/packages/playwright/src/index.ts:326:5)
        at /Users/maxschmitt/Developer/playwright/packages/playwright/src/worker/fixtureRunner.ts:116:9
        at Fixture._teardownInternal (/Users/maxschmitt/Developer/playwright/packages/playwright/src/worker/fixtureRunner.ts:160:7)
        at /Users/maxschmitt/Developer/playwright/packages/playwright/src/worker/testInfo.ts:364:11
        at TimeoutManager.withRunnable (/Users/maxschmitt/Developer/playwright/packages/playwright/src/worker/timeoutManager.ts:100:14)
        at TestInfoImpl._runWithTimeout (/Users/maxschmitt/Developer/playwright/packages/playwright/src/worker/testInfo.ts:362:7)
        at Fixture.teardown (/Users/maxschmitt/Developer/playwright/packages/playwright/src/worker/fixtureRunner.ts:138:11)
        at FixtureRunner.teardownScope (/Users/maxschmitt/Developer/playwright/packages/playwright/src/worker/fixtureRunner.ts:211:9)
        at /Users/maxschmitt/Developer/playwright/packages/playwright/src/worker/workerMain.ts:408:9
        at TestInfoImpl._runAsStep (/Users/maxschmitt/Developer/playwright/packages/playwright/src/worker/testInfo.ts:352:7)
        at WorkerMain._runTest (/Users/maxschmitt/Developer/playwright/packages/playwright/src/worker/workerMain.ts:385:5)
        at WorkerMain.runTestGroup (/Users/maxschmitt/Developer/playwright/packages/playwright/src/worker/workerMain.ts:231:11)
        at process.<anonymous> (/Users/maxschmitt/Developer/playwright/packages/playwright/src/common/process.ts:88:22)

We can fix it separately I think. We should re-visit our idea of making page.evaluate errors an error.cause + make this non-throwing.

@github-actions

This comment has been minimized.

@mxschmitt mxschmitt changed the title test: error context exception on page.evaluate fix(reporters): error context exception with page.evaluate Apr 22, 2025
Copy link
Member

@Skn0tt Skn0tt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this is the right fix. Could we walk parsedError to find the first error location that we can read instead?

@mxschmitt mxschmitt force-pushed the error-context-worker branch from de5bfdf to 1555606 Compare April 22, 2025 11:32
@github-actions

This comment has been minimized.

Copy link
Member

@Skn0tt Skn0tt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! cc @dgozman for final review.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Smrtnyk
Copy link

Smrtnyk commented Apr 22, 2025

after upgrade 1 of our tests started failing blocking the upgrade
error looks similar to this

Error: page.evaluate: Error: Call to when caused Illegal invocation
        at eval (eval at evaluate (:313:29), <anonymous>:23:25)
        at UtilityScript.evaluate (<anonymous>:315:16)
        at UtilityScript.<anonymous> (<anonymous>:1:44)
        at eval (eval at evaluate (:313:29), <anonymous>:23:25)
        at UtilityScript.evaluate (<anonymous>:315:16)
        at UtilityScript.<anonymous> (<anonymous>:1:44)

should I expect it to be fixed with this PR
or should I create a repro for this?

@mxschmitt
Copy link
Contributor Author

after upgrade 1 of our tests started failing blocking the upgrade error looks similar to this

Error: page.evaluate: Error: Call to when caused Illegal invocation
        at eval (eval at evaluate (:313:29), <anonymous>:23:25)
        at UtilityScript.evaluate (<anonymous>:315:16)
        at UtilityScript.<anonymous> (<anonymous>:1:44)
        at eval (eval at evaluate (:313:29), <anonymous>:23:25)
        at UtilityScript.evaluate (<anonymous>:315:16)
        at UtilityScript.<anonymous> (<anonymous>:1:44)

should I expect it to be fixed with this PR or should I create a repro for this?

Looks different, so a new bug would be appreciated!

source,
{
start: {
line: location.line,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should synchronize location and source variables - try loading source from the parsedError.location first, and then fallback to the test location and source.

@github-actions

This comment has been minimized.

@mxschmitt mxschmitt force-pushed the error-context-worker branch from 7bebbd5 to b18035f Compare April 22, 2025 17:21
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@mxschmitt mxschmitt requested a review from dgozman April 23, 2025 06:25
@mxschmitt mxschmitt merged commit c454681 into microsoft:main Apr 23, 2025
29 checks passed
@mxschmitt mxschmitt deleted the error-context-worker branch April 23, 2025 06:55
@github-actions
Copy link
Contributor

Test results for "tests 1"

4 flaky ⚠️ [firefox-page] › page/page-evaluate.spec.ts:424:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18
⚠️ [playwright-test] › ui-mode-test-output.spec.ts:80:5 › should show console messages for test @ubuntu-latest-node22-1
⚠️ [webkit-library] › library/trace-viewer.spec.ts:784:1 › should handle src=blob @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:345:5 › page screenshot › should work while navigating @webkit-ubuntu-22.04-node18

39063 passed, 799 skipped
✔️✔️✔️

Merge workflow run.

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

Successfully merging this pull request may close these issues.

4 participants