Skip to content

Commit

Permalink
Add logging for materia parsing failures (#1341)
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro authored Jul 21, 2024
1 parent f93f80d commit 733df89
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/Universalis.DbAccess/MarketBoard/ListingStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ ORDER BY unit_price
WorldId = reader.GetInt32(2),
Hq = reader.GetBoolean(3),
OnMannequin = reader.GetBoolean(4),
Materia = ReadMateriaFromReader(reader),
Materia = ReadMateriaFromReader(reader, query.WorldId, query.ItemId),
PricePerUnit = reader.GetInt32(6),
Quantity = reader.GetInt32(7),
DyeId = reader.GetInt32(8),
Expand Down Expand Up @@ -305,7 +305,7 @@ FROM listing t
WorldId = worldId,
Hq = reader.GetBoolean(3),
OnMannequin = reader.GetBoolean(4),
Materia = ReadMateriaFromReader(reader),
Materia = ReadMateriaFromReader(reader, worldId, itemId),
PricePerUnit = reader.GetInt32(6),
Quantity = reader.GetInt32(7),
DyeId = reader.GetInt32(8),
Expand Down Expand Up @@ -449,14 +449,14 @@ private static JArray ConvertMateriaToJArray(IList<Materia> materia)
});
}

private static List<Materia> ReadMateriaFromReader(NpgsqlDataReader reader)
private List<Materia> ReadMateriaFromReader(NpgsqlDataReader reader, int worldId, int itemId)
{
return reader.IsDBNull(5)
? new List<Materia>()
: ConvertMateriaFromJArray(reader.GetFieldValue<JArray>(5));
: ConvertMateriaFromJArray(reader.GetFieldValue<JArray>(5), worldId, itemId);
}

private static List<Materia> ConvertMateriaFromJArray(IEnumerable<JToken> materia)
private List<Materia> ConvertMateriaFromJArray(IEnumerable<JToken> materia, int worldId, int itemId)
{
return materia
.Select((m, i) =>
Expand All @@ -465,15 +465,14 @@ private static List<Materia> ConvertMateriaFromJArray(IEnumerable<JToken> materi
{
return new Materia { SlotId = m["slot_id"].Value<int>(), MateriaId = m["materia_id"].Value<int>() };
}
catch (ArgumentException)
catch (ArgumentException e)
{
return new Materia
{
SlotId = m[i]["slot_id"].Value<int>(),
MateriaId = m[i]["materia_id"].Value<int>(),
};
// Unsure why this happens, possibly inserted bad data at some point while debugging
_logger.LogError(e, "Failed to parse materia for world={}, item={}", worldId, itemId);
return null;
}
})
.Where(m => m is not null)
.ToList();
}
}

0 comments on commit 733df89

Please sign in to comment.