| 11641 | |
| 11642 | |
| 11643 | ResultType Line::LineError(char *aErrorText, ResultType aErrorType, char *aExtraInfo) |
| 11644 | { |
| 11645 | if (!aErrorText) |
| 11646 | aErrorText = "Unknown Error"; |
| 11647 | if (!aExtraInfo) |
| 11648 | aExtraInfo = ""; |
| 11649 | |
| 11650 | if (g_script.mErrorStdOut && !g_script.mIsReadyToExecute) // i.e. runtime errors are always displayed via dialog. |
| 11651 | { |
| 11652 | // JdeB said: |
| 11653 | // Just tested it in Textpad, Crimson and Scite. they all recognise the output and jump |
| 11654 | // to the Line containing the error when you double click the error line in the output |
| 11655 | // window (like it works in C++). Had to change the format of the line to: |
| 11656 | // printf("%s (%d) : ==> %s: \n%s \n%s\n",szInclude, nAutScriptLine, szText, szScriptLine, szOutput2 ); |
| 11657 | // MY: Full filename is required, even if it's the main file, because some editors (EditPlus) |
| 11658 | // seem to rely on that to determine which file and line number to jump to when the user double-clicks |
| 11659 | // the error message in the output window: |
| 11660 | printf("%s (%d): ==> %s\n", sSourceFile[mFileNumber], mLineNumber, aErrorText); // printf() does not signifantly increase the size of the EXE, probably because it shares most of the same code with sprintf(), etc. |
| 11661 | if (*aExtraInfo) |
| 11662 | printf(" Specifically: %s\n", aExtraInfo); |
| 11663 | } |
| 11664 | else |
| 11665 | { |
| 11666 | char source_file[MAX_PATH * 2]; |
| 11667 | if (mFileNumber) |
| 11668 | snprintf(source_file, sizeof(source_file), " in #include file \"%s\"", sSourceFile[mFileNumber]); |
| 11669 | else |
| 11670 | *source_file = '\0'; // Don't bother cluttering the display if it's the main script file. |
| 11671 | |
| 11672 | char buf[MSGBOX_TEXT_SIZE]; |
| 11673 | snprintf(buf, sizeof(buf), "%s%s: %-1.500s\n\n" // Keep it to a sane size in case it's huge. |
| 11674 | , aErrorType == WARN ? "Warning" : (aErrorType == CRITICAL_ERROR ? "Critical Error" : "Error") |
| 11675 | , source_file, aErrorText); |
| 11676 | if (*aExtraInfo) |
| 11677 | // Use format specifier to make sure really huge strings that get passed our |
| 11678 | // way, such as a var containing clipboard text, are kept to a reasonable size: |
| 11679 | snprintfcat(buf, sizeof(buf), "Specifically: %-1.100s%s\n\n" |
| 11680 | , aExtraInfo, strlen(aExtraInfo) > 100 ? "..." : ""); |
| 11681 | char *buf_marker = buf + strlen(buf); |
| 11682 | buf_marker = VicinityToText(buf_marker, sizeof(buf) - (buf_marker - buf)); |
| 11683 | if (aErrorType == CRITICAL_ERROR || (aErrorType == FAIL && !g_script.mIsReadyToExecute)) |
| 11684 | strlcpy(buf_marker, g_script.mIsRestart ? ("\n" OLD_STILL_IN_EFFECT) : ("\n" WILL_EXIT) |
| 11685 | , sizeof(buf) - (buf_marker - buf)); |
| 11686 | //buf_marker += strlen(buf_marker); |
| 11687 | g_script.mCurrLine = this; // This needs to be set in some cases where the caller didn't. |
| 11688 | //g_script.ShowInEditor(); |
| 11689 | MsgBox(buf); |
| 11690 | } |
| 11691 | |
| 11692 | if (aErrorType == CRITICAL_ERROR && g_script.mIsReadyToExecute) |
| 11693 | // Also ask the main message loop function to quit and announce to the system that |
| 11694 | // we expect it to quit. In most cases, this is unnecessary because all functions |
| 11695 | // called to get to this point will take note of the CRITICAL_ERROR and thus keep |
| 11696 | // return immediately, all the way back to main. However, there may cases |
| 11697 | // when this isn't true: |
| 11698 | // Note: Must do this only after MsgBox, since it appears that new dialogs can't |
| 11699 | // be created once it's done. Update: Using ExitApp() now, since it's known to be |
| 11700 | // more reliable: |
no test coverage detected