__zone_symbol__currentTask Error

2019-04-26 15:22发布

问题:

I get an Error:

{"__zone_symbol_currentTask":{"type":"microTask","state":"notScheduled","source":"Promise.then","zone":"angular","cancelFn":null,"runCount":0}}

And that's the code:

async getNewData(id: number, path: string, howMany: number) {
    let fileManagement: FileManagement = new FileManagement();
    let result: any = null;
    switch (id) {
        case 0:
            alert("pfad: " + path);
            await fileManagement.readFile(path + "Tasks/", "task_" + howMany + ".tsk").then((text) => {
                alert("text: " + text);
                result = JSON.parse(text);
                alert("ganz fertig");
            }).catch((error)=>{
                alert("nein, error: " + JSON.stringify(error));
            });
        default:
            result = JSON.parse(this.getDataFromComponent(id, howMany, path));
        //wenn komponenten aufgerufen werden sollen zum generieren
    }
    return result;
}
constructor(public navCtrl: NavController, private tts: TextToSpeech, navParams: NavParams) {
    this.path = navParams.get('path'); //PFAD DES ÜBUNGSORDNERS HIER ÜBERGEBEN
    this.newData.getNewData(0, this.path, this.fileCounter).then((data) => {
      this.buffer = data;
      this.fileCounter++;
      this.nextChoice(0);
    }).catch((error) => {
      alert(JSON.stringify(error)); //here the error is thrown
    });
  }

Could you please tell me why that is and how I can fix it? I would appreciate any answer!

回答1:

I should note that it is unlikely for anyone to see the original error in this code since it in part depends on external dependencies. Instead, this "answer" attempts to provide you with a way to identify why you are getting an incomplete error message and how you can identify the actual error message. I hope that helps!

Cause of Missing Error Info

The underlying issue you are encountering is being hidden by two facts:

  1. The __zone_symbol_currentTask is a property inserted into the Error object by Angular.
  2. JSON.stringify does not output the Error object's own properties (by default)

As a result, the only error property you are seeing in the JSONified output is that strange-looking property introduced by Angular.

Workaround

To log your underlying error detail, you might try the following:

JSON.stringify(err, Object.getOwnPropertyNames(err))

Though this would not generally be recommended, you could remove the property inserted by Angular if it really bothers you:

delete error.__zone_symbol__currentTask

See Also: Is it not possible to stringify an Error using JSON.stringify?