Skip to content

Commit

Permalink
add error stack check (#1900)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlie-777 authored Sep 12, 2022
1 parent f9f92f6 commit ac1d628
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions shared/AppInsightsCommon/Tests/Unit/src/Exception.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,30 @@ export class ExceptionTests extends AITestClass {
// Assert.deepEqual(stackFrame, stackFrameConverted);
}
});

this.testCase({
name: "StackFrame: ErrorStack can be exported from reason object of errorObj",
test: () => {
let errObj = {
reason:{
message: "message",
stack: "TypeError: undefined\n at Function.assign(<file>)"
}
};
let errDetail = {
src: "TypeError: undefined\n at Function.assign(<file>)",
obj:["TypeError: undefined"," at Function.assign(<file>)"]
};
let exception = Exception.CreateAutoException("message",
"url",
9,
0,
errObj
);

Assert.ok(exception.stackDetails);
Assert.deepEqual(exception.stackDetails, errDetail);
}
});
}
}
3 changes: 3 additions & 0 deletions shared/AppInsightsCommon/src/Telemetry/Exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ function _getStackFromErrorObj(errorObj:any): IStackDetails {
} else if (window && window["opera"] && errorObj[strMessage]) {
// Opera
details = _getOperaStack(errorObj.message);
} else if (errorObj["reason"] && errorObj.reason[strStack]) {
// UnhandledPromiseRejection
details = _convertStackObj(errorObj.reason[strStack]);
} else if (isString(errorObj)) {
details = _convertStackObj(errorObj);
} else {
Expand Down

0 comments on commit ac1d628

Please sign in to comment.