Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: print specific file instead of full stack trace for invalid data #410

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion msu/systems/serialization/serde_emulator.nut
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
{
local stackinfos = ::getstackinfos(2);
::logError(format("The type being read %s isn't the same as the type %s (with value: %s) stored in the Deserialization Emulator (%s -> %s : %i)", ::MSU.Serialization.DataType.getKeyForValue(_type), ::MSU.Serialization.DataType.getKeyForValue(this.SerializationData.getDataArray()[this.Idx].getType()), data.getData() + "", stackinfos.func == "unknown" ? "" : stackinfos.func, stackinfos.src, stackinfos.line));
::MSU.Log.printStackTrace(); // TODO: Temporary, should be removed once log spam issue is resolved
}
return data.getData();
}
Expand Down
24 changes: 19 additions & 5 deletions msu/systems/serialization/serialization_types/primitive_data.nut
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,24 @@

function __printInvalidDataError( _type, _data )
{
::logError(format("Storing invalid or unexpected data \'%s\' in container of type: %s", _data + "", ::MSU.Serialization.DataType.getKeyForValue(_type)));
// We have to print the full stack trace here because we cannot know for sure which level of stackinfos will be the actual source of the problem
// as it will be different if this is being instantiated by someone in their own function somewhere or if it is being instantiated
// by MSU functions e.g. ::MSU.Serialization.__convertValueFromBaseType
::MSU.Log.printStackTrace();
local level = 3;
local errorSource = "";
local infos = ::getstackinfos(level);
while (infos != null)
{
local src = infos.src;
if (src.len() < 4 || src.slice(0, 4) != "msu/" || src.len() < 9 || src.slice(0, 9) == "msu/hooks")
{
errorSource = format(" (%s -> %s : %i)", infos.func == "unknown" ? "" : infos.func, src, infos.line);
break;
}

infos = ::getstackinfos(++level);
}

::logError(format("Storing invalid or unexpected data \'%s\' (type %s) in container of type: %s%s", _data + "", typeof _data, ::MSU.Serialization.DataType.getKeyForValue(_type), errorSource));

if (errorSource == "")
::MSU.Log.printStackTrace();
}
}