Skip to content

Commit

Permalink
Move file reporting for script errors to ShowRuntimeError function
Browse files Browse the repository at this point in the history
  • Loading branch information
llde committed Aug 27, 2023
1 parent 24ed032 commit ade0ef5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
30 changes: 3 additions & 27 deletions obse/obse/ExpressionEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,7 @@ void ExpressionEvaluator::Error(const char* fmt, ...)
UInt16* opcodePtr = (UInt16*)((UInt8*)script->data + (*m_opcodeOffsetPtr - 4));
CommandInfo* cmd = g_scriptCommands.GetByOpcode(*opcodePtr);

// include mod filename, save having to ask users to figure it out themselves
const char* modName = "Savegame";
if (script->GetModIndex() != 0xFF)
{
modName = (*g_dataHandler)->GetNthModName(script->GetModIndex());
if (!modName || !modName[0])
modName = "Unknown";
}

ShowRuntimeError(script, "%s\n File: %s Offset: 0x%04X Command: %s", errorMsg, modName, m_baseOffset , cmd ? cmd->longName : "<unknown>");
ShowRuntimeError(script, "%s\n Offset: 0x%04X Command: %s", errorMsg, m_baseOffset , cmd ? cmd->longName : "<unknown>");
// if (m_flags.IsSet(kFlag_StackTraceOnError))
PrintStackTrace();
}
Expand All @@ -73,15 +64,8 @@ void ExpressionEvaluator::Error(const char* fmt, Operator* tok, ...)
else {
sprintf_s(errorMsgTok, 0x400, "<unknow>");
}
const char* modName = "Savegame";
if (script->GetModIndex() != 0xFF)
{
modName = (*g_dataHandler)->GetNthModName(script->GetModIndex());
if (!modName || !modName[0])
modName = "Unknown";
}

ShowRuntimeError(script, "%s\n File: %s Offset: 0x%04X Operator: %s", errorMsg, modName, m_baseOffset, errorMsgTok);
ShowRuntimeError(script, "%s\n Offset: 0x%04X Operator: %s", errorMsg, m_baseOffset, errorMsgTok);
// if (m_flags.IsSet(kFlag_StackTraceOnError))
// PrintStackTrace();
}
Expand Down Expand Up @@ -130,16 +114,8 @@ void ExpressionEvaluator::Error(const char* fmt, ScriptToken* tok, ...)
// UInt16* opcodePtr = (UInt16*)((UInt8*)script->data + (*m_opcodeOffsetPtr - 4));
// cmd = g_scriptCommands.GetByOpcode(*opcodePtr);
// }
// include mod filename, save having to ask users to figure it out themselves
const char* modName = "Savegame";
if (script->GetModIndex() != 0xFF)
{
modName = (*g_dataHandler)->GetNthModName(script->GetModIndex());
if (!modName || !modName[0])
modName = "Unknown";
}

ShowRuntimeError(script, "%s\n File: %s Offset: 0x%04X Command: %s", errorMsg, modName, m_baseOffset, buf);
ShowRuntimeError(script, "%s\n Offset: 0x%04X Command: %s", errorMsg, m_baseOffset, buf);
// if (m_flags.IsSet(kFlag_StackTraceOnError))
// PrintStackTrace();
}
Expand Down
11 changes: 10 additions & 1 deletion obse/obse/ScriptUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,16 @@ std::string ExpressionParser::GetCurToken()
void ShowRuntimeError(Script* script, const char* fmt, ...)
{
char errorHeader[0x400];
sprintf_s(errorHeader, 0x400, "Error in script %08x", script ? script->refID : 0);
// include mod filename, save having to ask users to figure it out themselves
const char* modName = "Savegame";
if (script->GetModIndex() != 0xFF)
{
modName = (*g_dataHandler)->GetNthModName(script->GetModIndex());
if (!modName || !modName[0])
modName = "Unknown";
}

sprintf_s(errorHeader, 0x400, "Error in script %08x: %s in File: %s", script ? script->refID : 0, script ? script->GetEditorID2() : "<No EDID>", modName);

va_list args;
va_start(args, fmt);
Expand Down

0 comments on commit ade0ef5

Please sign in to comment.