From 509dfda5e5ee314749f4b3e3551b4f90c7ebee97 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Thu, 10 Dec 2020 13:15:18 +0100 Subject: [PATCH] clean up error handling in d2game/d2player/inventory.go and d2core/d2item/diablo2item/ --- d2core/d2item/diablo2item/item_property_test.go | 10 +++++++++- d2game/d2player/game_controls.go | 7 ++++++- d2game/d2player/inventory.go | 10 ++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/d2core/d2item/diablo2item/item_property_test.go b/d2core/d2item/diablo2item/item_property_test.go index 5736382f..ec932ff5 100644 --- a/d2core/d2item/diablo2item/item_property_test.go +++ b/d2core/d2item/diablo2item/item_property_test.go @@ -419,9 +419,17 @@ var testAssetManager *d2asset.AssetManager var testItemFactory *ItemFactory func TestSetup(t *testing.T) { + var err error + testAssetManager = &d2asset.AssetManager{} testAssetManager.Records = &d2records.RecordManager{} - testItemFactory, _ = NewItemFactory(testAssetManager) + + testItemFactory, err = NewItemFactory(testAssetManager) + if err != nil { + t.Error(err) + return + } + testAssetManager.Records.Item.Stats = itemStatCosts testAssetManager.Records.Character.Stats = charStats testAssetManager.Records.Skill.Details = skillDetails diff --git a/d2game/d2player/game_controls.go b/d2game/d2player/game_controls.go index b9608ae1..ce6ea2fa 100644 --- a/d2game/d2player/game_controls.go +++ b/d2game/d2player/game_controls.go @@ -208,7 +208,12 @@ func NewGameControls( heroStatsPanel := NewHeroStatsPanel(asset, ui, hero.Name(), hero.Class, l, hero.Stats) questLog := NewQuestLog(asset, ui, l, hero.Act) - inventory := NewInventory(asset, ui, l, hero.Gold, inventoryRecord) + + inventory, err := NewInventory(asset, ui, l, hero.Gold, inventoryRecord) + if err != nil { + return nil, err + } + skilltree := newSkillTree(hero.Skills, hero.Class, asset, l, ui) miniPanel := newMiniPanel(asset, ui, l, isSinglePlayer) diff --git a/d2game/d2player/inventory.go b/d2game/d2player/inventory.go index 3a6fde86..58c31f23 100644 --- a/d2game/d2player/inventory.go +++ b/d2game/d2player/inventory.go @@ -32,11 +32,13 @@ func NewInventory(asset *d2asset.AssetManager, ui *d2ui.UIManager, l d2util.LogLevel, gold int, - record *d2records.InventoryRecord) *Inventory { + record *d2records.InventoryRecord) (*Inventory, error) { itemTooltip := ui.NewTooltip(d2resource.FontFormal11, d2resource.PaletteStatic, d2ui.TooltipXCenter, d2ui.TooltipYBottom) - // https://github.com/OpenDiablo2/OpenDiablo2/issues/797 - itemFactory, _ := diablo2item.NewItemFactory(asset) + itemFactory, err := diablo2item.NewItemFactory(asset) + if err != nil { + return nil, fmt.Errorf("during creating new item factory: %s", err) + } inventory := &Inventory{ asset: asset, @@ -54,7 +56,7 @@ func NewInventory(asset *d2asset.AssetManager, inventory.Logger.SetLevel(l) inventory.Logger.SetPrefix(logPrefix) - return inventory + return inventory, nil } // Inventory represents the inventory