| 11709 | |
| 11710 | |
| 11711 | ResultType Script::ScriptError(char *aErrorText, char *aExtraInfo) //, ResultType aErrorType) |
| 11712 | // Even though this is a Script method, including it here since it shares |
| 11713 | // a common theme with the other error-displaying functions: |
| 11714 | { |
| 11715 | if (mCurrLine) |
| 11716 | // If a line is available, do LineError instead since it's more specific. |
| 11717 | // If an error occurs before the script is ready to run, assume it's always critical |
| 11718 | // in the sense that the program will exit rather than run the script. |
| 11719 | // Update: It's okay to return FAIL in this case. CRITICAL_ERROR should |
| 11720 | // be avoided whenever OK and FAIL are sufficient by themselves, because |
| 11721 | // otherwise, callers can't use the NOT operator to detect if a function |
| 11722 | // failed (since FAIL is value zero, but CRITICAL_ERROR is non-zero): |
| 11723 | return mCurrLine->LineError(aErrorText, FAIL, aExtraInfo); |
| 11724 | // Otherwise: The fact that mCurrLine is NULL means that the line currently being loaded |
| 11725 | // has not yet been successfully added to the linked list. Such errors will always result |
| 11726 | // in the program exiting. |
| 11727 | if (!aErrorText) |
| 11728 | aErrorText = "Unknown Error"; |
| 11729 | if (!aExtraInfo) // In case the caller explicitly called it with NULL. |
| 11730 | aExtraInfo = ""; |
| 11731 | |
| 11732 | if (g_script.mErrorStdOut && !g_script.mIsReadyToExecute) // i.e. runtime errors are always displayed via dialog. |
| 11733 | { |
| 11734 | // See LineError() for details. |
| 11735 | printf("%s (%d): ==> %s\n", Line::sSourceFile[mCurrFileNumber], mCurrLineNumber, aErrorText); |
| 11736 | if (*aExtraInfo) |
| 11737 | printf(" Specifically: %s\n", aExtraInfo); |
| 11738 | } |
| 11739 | else |
| 11740 | { |
| 11741 | char source_file[MAX_PATH * 2]; |
| 11742 | if (mCurrFileNumber) |
| 11743 | snprintf(source_file, sizeof(source_file), " in #include file \"%s\"", Line::sSourceFile[mCurrFileNumber]); |
| 11744 | else |
| 11745 | *source_file = '\0'; // Don't bother cluttering the display if it's the main script file. |
| 11746 | |
| 11747 | char buf[MSGBOX_TEXT_SIZE]; |
| 11748 | snprintf(buf, sizeof(buf), "Error at line %u%s%s." // Don't call it "critical" because it's usually a syntax error. |
| 11749 | "\n\nLine Text: %-1.100s%s" |
| 11750 | "\nError: %-1.500s" |
| 11751 | "\n\n%s" |
| 11752 | , mCurrLineNumber, source_file, mCurrLineNumber ? "" : " (unknown)" |
| 11753 | , aExtraInfo // aExtraInfo defaults to "" so this is safe. |
| 11754 | , strlen(aExtraInfo) > 100 ? "..." : "" |
| 11755 | , aErrorText |
| 11756 | , mIsRestart ? OLD_STILL_IN_EFFECT : WILL_EXIT |
| 11757 | ); |
| 11758 | //ShowInEditor(); |
| 11759 | MsgBox(buf); |
| 11760 | } |
| 11761 | return FAIL; // See above for why it's better to return FAIL than CRITICAL_ERROR. |
| 11762 | } |
| 11763 | |
| 11764 | |
| 11765 |
no test coverage detected