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

ng test window.onerror ErrorEvent contains Script Error instead of actual error #11966

Closed
james-schwartzkopf opened this issue Aug 21, 2018 · 1 comment · Fixed by #11970
Closed
Labels
area: devkit/build-angular freq1: low Only reported by a handful of users who observe it rarely severity5: regression type: bug/fix
Milestone

Comments

@james-schwartzkopf
Copy link

Bug Report or Feature Request (mark with an x)

- [X ] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [X] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

@angular-devkit/build-angular >= 0.7.0

passes with 0.6.8, fails with anything after 0.7.0

ng --version

Angular CLI: 6.1.4
Node: 10.9.0
OS: win32 x64
Angular: 6.1.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.7.4
@angular-devkit/build-angular     0.7.4
@angular-devkit/build-optimizer   0.7.4
@angular-devkit/build-webpack     0.7.4
@angular-devkit/core              0.7.4
@angular-devkit/schematics        0.7.4
@angular/cli                      6.1.4
@ngtools/webpack                  6.1.4
@schematics/angular               0.7.4
@schematics/update                0.7.4
rxjs                              6.2.2
typescript                        2.7.2
webpack                           4.9.2

Repro steps

ng new on-error
cd on-error
cat > src/app/test-onerror.spec.ts << 'EOF'
import { timer } from 'rxjs';

describe('window.onerror', () => {
  it('returns "Script Error." instead of actual error', async () => {
    setTimeout(() => { throw new Error('Go boom'); });

    const onErrorSpy = spyOn(window, 'onerror');

    await timer().toPromise();

    expect(onErrorSpy).toHaveBeenCalledTimes(1);
    const ev: ErrorEvent = onErrorSpy.calls.argsFor(0)[0];
    console.log(`ErrorEvent
      filename: '${ev.filename}':'${ev.lineno}'
      message: '${ev.message}'
      error: '${ev.error && ev.error.message}'`
    );
    expect(ev.error).not.toBe(null);
  });
});
EOF
ng test --watch false

The log given by the failure

$ ng test --watch false
21 08 2018 16:42:51.305:WARN [karma]: Port 9876 in use
21 08 2018 16:42:51.309:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9877/
21 08 2018 16:42:51.309:INFO [launcher]: Launching browser Chrome with unlimited concurrency
21 08 2018 16:42:51.340:INFO [launcher]: Starting browser Chrome
21 08 2018 16:42:54.772:INFO [Chrome 68.0.3440 (Windows 10.0.0)]: Connected on socket Z7nV7JlOQnNqP43BAAAA with id 83287909
LOG: 'ErrorEvent
      filename: '':'0'
      message: 'Script error.'
      error: 'null''
Chrome 68.0.3440 (Windows 10.0.0): Executed 1 of 4 SUCCESS (0 secs / 0.044 secs)
LOG: 'ErrorEvent
      filename: '':'0'
      message: 'Script error.'
Chrome 68.0.3440 (Windows 10.0.0) window.onerror returns "Script Error." instead of actual error FAILED
        Expected null not to be null.
            at eval (webpack:///./src/app/test-onerror.spec.ts?:54:42)
            at step (webpack:///./src/app/test-onerror.spec.ts?:33:23)
            at Object.eval [as next] (webpack:///./src/app/test-onerror.spec.ts?:14:53)
            at fulfilled (webpack:///./src/app/test-onerror.spec.ts?:5:58)
Chrome 68.0.3440 (Windows 10.0.0): Executed 2 of 4 (1 FAILED) (0 secs / 0.05 secs)
Chrome 68.0.3440 (Windows 10.0.0) window.onerror returns "Script Error." instead of actual error FAILED
        Expected null not to be null.
            at eval (webpack:///./src/app/test-onerror.spec.ts?:54:42)
            at step (webpack:///./src/app/test-onerror.spec.ts?:33:23)
            at Object.eval [as next] (webpack:///./src/app/test-onerror.spec.ts?:14:53)
Chrome 68.0.3440 (Windows 10.0.0): Executed 4 of 4 (1 FAILED) (0.212 secs / 0.197 secs)

Desired functionality

The ErrorEvent passed to window.onerror should contain the error:

LOG: 'ErrorEvent
      filename: 'http://localhost:9877/_karma_webpack_/vendor.js':'71851'
      message: 'Uncaught Error: Go boom'
Chrome 68.0.3440 (Windows 10.0.0): Executed 4 of 4 SUCCESS (0.122 secs / 0.171 secs)

Mention any other details that might be useful

Looking at this stack overflow, I assume this is a cross origin issue. I noticed the context.html has the crossorigin attribute set on all the script tags, so not sure what's actually going wrong.
https://stackoverflow.com/questions/5913978/cryptic-script-error-reported-in-javascript-in-chrome-and-firefox

@ngbot ngbot bot added this to the needsTriage milestone Aug 22, 2018
@filipesilva filipesilva added freq1: low Only reported by a handful of users who observe it rarely severity5: regression type: bug/fix labels Aug 24, 2018
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Aug 24, 2018
vikerman pushed a commit that referenced this issue Aug 28, 2018
)

Checking the stack trace in the issue one can noticed that the paths for the components are being served via the `webpack://` protocol which is causing a `cors` issue between `http` and `webpack` protocol

This PR removed the `webpack` protocol from the `devtoolModuleFilenameTemplate`

Closes #11966
vikerman pushed a commit that referenced this issue Aug 29, 2018
)

Checking the stack trace in the issue one can noticed that the paths for the components are being served via the `webpack://` protocol which is causing a `cors` issue between `http` and `webpack` protocol

This PR removed the `webpack` protocol from the `devtoolModuleFilenameTemplate`

Closes #11966
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: devkit/build-angular freq1: low Only reported by a handful of users who observe it rarely severity5: regression type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants