Skip to content

APP_INITIALIZER: rejected promise throws "Cannot read property 'ngOriginalError' of undefined" #21252

@SteveVanOpstal

Description

@SteveVanOpstal

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

The following provider will cause Angular to throw an error.

const INIT_PROVIDER = {
  provide: APP_INITIALIZER,
  useFactory: initFactory,
  multi: true
};

function initFactory() {
  return () => init();
}

function init() {
  return new Promise((resolve, reject) => {
    reject();
  });
}

The error occurs here:

export function getOriginalError(error: Error): Error {
return (error as any)[ERROR_ORIGINAL_ERROR];
}

ERROR_ORIGINAL_ERROR ('ngOriginalError') doesn't exist on error at this point.

Related: #18523

Expected behavior

The error should not occur. Unsure on what should happen in case the Promise is rejected but logging an error and continue operating seems like a good solution.

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/angular-gitter-p6cngp

Open up the console and following error will appear:

Unhandled Promise rejection: Cannot read property 'ngOriginalError' of undefined

Environment


Angular version: 5.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimecore: bootstrapfreq2: mediumstate: has PRtype: bug/fix

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions