diff --git a/src/Universalis.DbAccess/MarketBoard/ListingStore.cs b/src/Universalis.DbAccess/MarketBoard/ListingStore.cs index a628a21a..20b92f0a 100644 --- a/src/Universalis.DbAccess/MarketBoard/ListingStore.cs +++ b/src/Universalis.DbAccess/MarketBoard/ListingStore.cs @@ -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), @@ -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), @@ -449,14 +449,14 @@ private static JArray ConvertMateriaToJArray(IList materia) }); } - private static List ReadMateriaFromReader(NpgsqlDataReader reader) + private List ReadMateriaFromReader(NpgsqlDataReader reader, int worldId, int itemId) { return reader.IsDBNull(5) ? new List() - : ConvertMateriaFromJArray(reader.GetFieldValue(5)); + : ConvertMateriaFromJArray(reader.GetFieldValue(5), worldId, itemId); } - private static List ConvertMateriaFromJArray(IEnumerable materia) + private List ConvertMateriaFromJArray(IEnumerable materia, int worldId, int itemId) { return materia .Select((m, i) => @@ -465,15 +465,14 @@ private static List ConvertMateriaFromJArray(IEnumerable materi { return new Materia { SlotId = m["slot_id"].Value(), MateriaId = m["materia_id"].Value() }; } - catch (ArgumentException) + catch (ArgumentException e) { - return new Materia - { - SlotId = m[i]["slot_id"].Value(), - MateriaId = m[i]["materia_id"].Value(), - }; + // 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(); } } \ No newline at end of file