| 12883 | |
| 12884 | |
| 12885 | ResultType Script::ScriptError(LPCTSTR aErrorText, LPCTSTR aExtraInfo) //, ResultType aErrorType) |
| 12886 | // Even though this is a Script method, including it here since it shares |
| 12887 | // a common theme with the other error-displaying functions: |
| 12888 | { |
| 12889 | if (mCurrLine) |
| 12890 | // If a line is available, do LineError instead since it's more specific. |
| 12891 | // If an error occurs before the script is ready to run, assume it's always critical |
| 12892 | // in the sense that the program will exit rather than run the script. |
| 12893 | // Update: It's okay to return FAIL in this case. CRITICAL_ERROR should |
| 12894 | // be avoided whenever OK and FAIL are sufficient by themselves, because |
| 12895 | // otherwise, callers can't use the NOT operator to detect if a function |
| 12896 | // failed (since FAIL is value zero, but CRITICAL_ERROR is non-zero): |
| 12897 | return mCurrLine->LineError(aErrorText, FAIL, aExtraInfo); |
| 12898 | // Otherwise: The fact that mCurrLine is NULL means that the line currently being loaded |
| 12899 | // has not yet been successfully added to the linked list. Such errors will always result |
| 12900 | // in the program exiting. |
| 12901 | if (!aErrorText) |
| 12902 | aErrorText = _T("Unk"); // Placeholder since it shouldn't be NULL. |
| 12903 | if (!aExtraInfo) // In case the caller explicitly called it with NULL. |
| 12904 | aExtraInfo = _T(""); |
| 12905 | |
| 12906 | if (g_script.mErrorStdOut && !g_script.mIsReadyToExecute) // i.e. runtime errors are always displayed via dialog. |
| 12907 | { |
| 12908 | // See LineError() for details. |
| 12909 | PrintErrorStdOut(aErrorText, aExtraInfo, mCurrFileIndex, mCombinedLineNumber); |
| 12910 | } |
| 12911 | else |
| 12912 | { |
| 12913 | TCHAR buf[MSGBOX_TEXT_SIZE], *cp = buf; |
| 12914 | int buf_space_remaining = (int)_countof(buf); |
| 12915 | |
| 12916 | if (mCombinedLineNumber || mCurrFileIndex) |
| 12917 | { |
| 12918 | cp += sntprintf(cp, buf_space_remaining, _T("Error at line %u"), mCombinedLineNumber); // Don't call it "critical" because it's usually a syntax error. |
| 12919 | buf_space_remaining = (int)(_countof(buf) - (cp - buf)); |
| 12920 | } |
| 12921 | |
| 12922 | if (mCurrFileIndex) |
| 12923 | { |
| 12924 | cp += sntprintf(cp, buf_space_remaining, _T(" in #include file \"%s\""), Line::sSourceFile[mCurrFileIndex]); |
| 12925 | buf_space_remaining = (int)(_countof(buf) - (cp - buf)); |
| 12926 | } |
| 12927 | //else don't bother cluttering the display if it's the main script file. |
| 12928 | |
| 12929 | if (mCombinedLineNumber || mCurrFileIndex) |
| 12930 | { |
| 12931 | cp += sntprintf(cp, buf_space_remaining, _T(".\n\n")); |
| 12932 | buf_space_remaining = (int)(_countof(buf) - (cp - buf)); |
| 12933 | } |
| 12934 | |
| 12935 | if (*aExtraInfo) |
| 12936 | { |
| 12937 | cp += sntprintf(cp, buf_space_remaining, _T("Line Text: %-1.100s%s\nError: ") // i.e. the word "Error" is omitted as being too noisy when there's no ExtraInfo to put into the dialog. |
| 12938 | , aExtraInfo // aExtraInfo defaults to "" so this is safe. |
| 12939 | , _tcslen(aExtraInfo) > 100 ? _T("...") : _T("")); |
| 12940 | buf_space_remaining = (int)(_countof(buf) - (cp - buf)); |
| 12941 | } |
| 12942 | sntprintf(cp, buf_space_remaining, _T("%s\n\n%s"), aErrorText, mIsRestart ? OLD_STILL_IN_EFFECT : WILL_EXIT); |
no test coverage detected