- improved error reporting for badly defined translations.

This needs to be handled by the caller for all use cases because the translation parser lacks the context to do a proper error report.
This commit is contained in:
Christoph Oelckers 2018-12-16 09:56:53 +01:00
parent a96b86b13b
commit a38e75db00
4 changed files with 150 additions and 138 deletions

View File

@ -633,8 +633,6 @@ bool FRemapTable::AddToTranslation(const char *range)
sc.OpenMem("translation", range, int(strlen(range))); sc.OpenMem("translation", range, int(strlen(range)));
sc.SetCMode(true); sc.SetCMode(true);
try
{
sc.MustGetToken(TK_IntConst); sc.MustGetToken(TK_IntConst);
start = sc.Number; start = sc.Number;
sc.MustGetToken(':'); sc.MustGetToken(':');
@ -770,12 +768,6 @@ bool FRemapTable::AddToTranslation(const char *range)
pal2 = sc.Number; pal2 = sc.Number;
return AddIndexRange(start, end, pal1, pal2); return AddIndexRange(start, end, pal1, pal2);
} }
}
catch (CRecoverableError &err)
{
Printf("Error in translation '%s':\n%s\n", range, err.GetMessage());
return false;
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -1529,7 +1521,16 @@ void R_ParseTrnslate()
do do
{ {
sc.MustGetToken(TK_StringConst); sc.MustGetToken(TK_StringConst);
try
{
NewTranslation.AddToTranslation(sc.String); NewTranslation.AddToTranslation(sc.String);
}
catch (CRecoverableError &err)
{
sc.ScriptMessage("Error in translation '%s':\n" TEXTCOLOR_YELLOW "%s\n", sc.String, err.GetMessage());
}
} while (sc.CheckToken(',')); } while (sc.CheckToken(','));
int trans = NewTranslation.StoreTranslation(TRANSLATION_Custom); int trans = NewTranslation.StoreTranslation(TRANSLATION_Custom);

View File

@ -1120,7 +1120,7 @@ void FScanner::ScriptMessage (const char *message, ...)
va_end (arglist); va_end (arglist);
} }
Printf (TEXTCOLOR_RED "Script error, \"%s\" line %d:\n" TEXTCOLOR_RED "%s\n", ScriptName.GetChars(), Printf (TEXTCOLOR_RED "Script error, \"%s\"" TEXTCOLOR_RED "line %d:\n" TEXTCOLOR_RED "%s\n", ScriptName.GetChars(),
AlreadyGot? AlreadyGotLine : Line, composed.GetChars()); AlreadyGot? AlreadyGotLine : Line, composed.GetChars());
} }

View File

@ -729,7 +729,6 @@ DEFINE_PROPERTY(translation, L, Actor)
else else
{ {
FRemapTable CurrentTranslation; FRemapTable CurrentTranslation;
bool success = true;
CurrentTranslation.MakeIdentity(); CurrentTranslation.MakeIdentity();
for(int i = 1; i < PROP_PARM_COUNT; i++) for(int i = 1; i < PROP_PARM_COUNT; i++)
@ -744,14 +743,17 @@ DEFINE_PROPERTY(translation, L, Actor)
else else
{ {
// parse all ranges to get a complete list of errors, if more than one range fails. // parse all ranges to get a complete list of errors, if more than one range fails.
success |= CurrentTranslation.AddToTranslation(str); try
{
CurrentTranslation.AddToTranslation(str);
}
catch (CRecoverableError &err)
{
bag.ScriptPosition.Message(MSG_WARNING, "Error in translation '%s':\n" TEXTCOLOR_CYAN "%s\n", str, err.GetMessage());
}
} }
} }
defaults->Translation = CurrentTranslation.StoreTranslation (TRANSLATION_Decorate); defaults->Translation = CurrentTranslation.StoreTranslation (TRANSLATION_Decorate);
if (!success)
{
bag.ScriptPosition.Message(MSG_WARNING, "Failed to parse translation");
}
} }
} }

View File

@ -49,6 +49,7 @@
#include "v_video.h" #include "v_video.h"
#include "v_text.h" #include "v_text.h"
#include "cmdlib.h" #include "cmdlib.h"
#include "doomerrors.h"
// On the Alpha, accessing the shorts directly if they aren't aligned on a // On the Alpha, accessing the shorts directly if they aren't aligned on a
// 4-byte boundary causes unaligned access warnings. Why it does this at // 4-byte boundary causes unaligned access warnings. Why it does this at
@ -954,8 +955,16 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part, TexInit &init)
do do
{ {
sc.MustGetString(); sc.MustGetString();
try
{
part.Translation->AddToTranslation(sc.String); part.Translation->AddToTranslation(sc.String);
} }
catch (CRecoverableError &err)
{
sc.ScriptMessage("Error in translation '%s':\n" TEXTCOLOR_YELLOW "%s\n", sc.String, err.GetMessage());
}
}
while (sc.CheckString(",")); while (sc.CheckString(","));
} }