Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Show JS exception details for FATAL ERROR message
Browse files Browse the repository at this point in the history
If ChakraShim fails to initialize, there is no clear information on what is going on. This happened with the latest Windows update.

Suggested change shows the details of JS exception (if any)
  • Loading branch information
obastemur authored and Jianchun Xu committed Jan 6, 2016
1 parent f44ff42 commit d1e310e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions deps/chakrashim/src/jsrtutils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -866,12 +866,36 @@ void Unimplemented(const char * message) {
}

void Fatal(const char * format, ...) {
bool hasException;
JsErrorCode errorCode;
JsValueRef exceptionRef;
JsValueRef stackRef;
JsValueRef strErrorRef;
size_t stringLength;
const wchar_t* strError;

va_list args;
va_start(args, format);
fprintf(stderr, "FATAL ERROR: ");
vfprintf(stderr, format, args);
va_end(args);

errorCode = JsHasException(&hasException);
if (!hasException || errorCode != JsNoError) {
if (errorCode != JsNoError)
fprintf(stderr, "\nImportant: While trying to check Javascript "
"exception, JsHasException has also failed.\n");
else
fprintf(stderr, "\nImportant: This didn't happen because of an "
"uncaught Javascript exception.\n");
}
else if (JsGetAndClearException(&exceptionRef) == JsNoError &&
GetProperty(exceptionRef, L"stack", &stackRef) == JsNoError &&
JsConvertValueToString(stackRef, &strErrorRef) == JsNoError &&
JsStringToPointer(strErrorRef, &strError, &stringLength) == JsNoError) {
fwprintf(stderr, L"\n%s\n", strError);
}

#ifdef DEBUG
__debugbreak();
#endif
Expand Down

0 comments on commit d1e310e

Please sign in to comment.