From 74feb9d1d8031f508b7b28e7c925f0617fe03814 Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Thu, 3 Oct 2019 20:38:24 -0400 Subject: [PATCH] Better error messages Improve context for consistency check errors in item groups. Improve errors for undefined item (group) types in mapgen. --- src/item_factory.cpp | 2 +- src/item_group.cpp | 18 +++++++++--------- src/item_group.h | 8 ++++---- src/mapgen.cpp | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/item_factory.cpp b/src/item_factory.cpp index 1ffe6ab413aef..627104d799be7 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -1178,7 +1178,7 @@ void Item_factory::check_definitions() const } } for( const auto &elem : m_template_groups ) { - elem.second->check_consistency(); + elem.second->check_consistency( elem.first ); } } diff --git a/src/item_group.cpp b/src/item_group.cpp index 9fb9da64b94cd..9a8f22d35905d 100644 --- a/src/item_group.cpp +++ b/src/item_group.cpp @@ -114,15 +114,15 @@ Item_spawn_data::ItemList Single_item_creator::create( const time_point &birthda return result; } -void Single_item_creator::check_consistency() const +void Single_item_creator::check_consistency( const std::string &context ) const { if( type == S_ITEM ) { if( !item::type_is_defined( id ) ) { - debugmsg( "item id %s is unknown", id.c_str() ); + debugmsg( "item id %s is unknown (in %s)", id, context ); } } else if( type == S_ITEM_GROUP ) { if( !item_group::group_is_defined( id ) ) { - debugmsg( "item group id %s is unknown", id.c_str() ); + debugmsg( "item group id %s is unknown (in %s)", id, context ); } } else if( type == S_NONE ) { // this is okay, it will be ignored @@ -130,7 +130,7 @@ void Single_item_creator::check_consistency() const debugmsg( "Unknown type of Single_item_creator: %d", static_cast( type ) ); } if( modifier ) { - modifier->check_consistency(); + modifier->check_consistency( context ); } } @@ -301,13 +301,13 @@ void Item_modifier::modify( item &new_item ) const } } -void Item_modifier::check_consistency() const +void Item_modifier::check_consistency( const std::string &context ) const { if( ammo != nullptr ) { - ammo->check_consistency(); + ammo->check_consistency( "ammo of " + context ); } if( container != nullptr ) { - container->check_consistency(); + container->check_consistency( "container of " + context ); } if( with_ammo < 0 || with_ammo > 100 ) { debugmsg( "Item modifier's ammo chance %d is out of range", with_ammo ); @@ -432,10 +432,10 @@ item Item_group::create_single( const time_point &birthday, RecursionList &rec ) return item( null_item_id, birthday ); } -void Item_group::check_consistency() const +void Item_group::check_consistency( const std::string &context ) const { for( const auto &elem : items ) { - ( elem )->check_consistency(); + ( elem )->check_consistency( "item in " + context ); } } diff --git a/src/item_group.h b/src/item_group.h index c2be082a8706d..a727be8b5b031 100644 --- a/src/item_group.h +++ b/src/item_group.h @@ -127,7 +127,7 @@ class Item_spawn_data * Check item / spawn settings for consistency. Includes * checking for valid item types and valid settings. */ - virtual void check_consistency() const = 0; + virtual void check_consistency( const std::string &context ) const = 0; /** * For item blacklisted, remove the given item from this and * all linked groups. @@ -186,7 +186,7 @@ class Item_modifier Item_modifier( Item_modifier && ) = default; void modify( item &new_item ) const; - void check_consistency() const; + void check_consistency( const std::string &context ) const; bool remove_item( const Item_tag &itemid ); // Currently these always have the same chance as the item group it's part of, but @@ -233,7 +233,7 @@ class Single_item_creator : public Item_spawn_data ItemList create( const time_point &birthday, RecursionList &rec ) const override; item create_single( const time_point &birthday, RecursionList &rec ) const override; - void check_consistency() const override; + void check_consistency( const std::string &context ) const override; bool remove_item( const Item_tag &itemid ) override; bool has_item( const Item_tag &itemid ) const override; std::set every_item() const override; @@ -277,7 +277,7 @@ class Item_group : public Item_spawn_data ItemList create( const time_point &birthday, RecursionList &rec ) const override; item create_single( const time_point &birthday, RecursionList &rec ) const override; - void check_consistency() const override; + void check_consistency( const std::string &context ) const override; bool remove_item( const Item_tag &itemid ) override; bool has_item( const Item_tag &itemid ) const override; std::set every_item() const override; diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 52af10caad1e2..03496d9a60fef 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -1016,7 +1016,7 @@ class jmapgen_liquid_item : public jmapgen_piece , liquid( jsi.get_string( "liquid" ) ) , chance( jsi, "chance", 1, 1 ) { if( !item::type_is_defined( itype_id( liquid ) ) ) { - set_mapgen_defer( jsi, "liquid", "no such item type" ); + set_mapgen_defer( jsi, "liquid", "no such item type '" + liquid + "'" ); } } void apply( mapgendata &dat, const jmapgen_int &x, const jmapgen_int &y ) const override { @@ -1045,7 +1045,7 @@ class jmapgen_item_group : public jmapgen_piece group_id( jsi.get_string( "item" ) ) , chance( jsi, "chance", 1, 1 ) { if( !item_group::group_is_defined( group_id ) ) { - set_mapgen_defer( jsi, "item", "no such item type" ); + set_mapgen_defer( jsi, "item", "no such item group '" + group_id + "'" ); } repeat = jmapgen_int( jsi, "repeat", 1, 1 ); } @@ -1075,7 +1075,7 @@ class jmapgen_loot : public jmapgen_piece set_mapgen_defer( jsi, "group", "no such item group" ); } if( !name.empty() && !item::type_is_defined( name ) ) { - set_mapgen_defer( jsi, "item", "no such item type" ); + set_mapgen_defer( jsi, "item", "no such item type '" + name + "'" ); } // All the probabilities are 100 because we do the roll in @ref apply.