From e32d9e64a768f276e04fe79c14f1b28d88bd4185 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 8 Mar 2006 18:24:56 +0000 Subject: Added much better error location. --- binary.cc | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'binary.cc') diff --git a/binary.cc b/binary.cc index 8816078d..9f34af95 100644 --- a/binary.cc +++ b/binary.cc @@ -621,9 +621,29 @@ unsigned int read_binary_journal(std::istream& in, std::pair result = commodity_base_t::commodities.insert (base_commodities_pair(commodity->symbol, commodity)); - if (! result.second) - throw error(std::string("Failed to read base commodity from cache: ") + - commodity->symbol); + if (! result.second) { + base_commodities_map::iterator c = + commodity_base_t::commodities.find(commodity->symbol); + + // It's possible the user might have used a commodity in a value + // expression passed to an option, we'll just override the + // flags, but keep the commodity pointer intact. + if (c == commodity_base_t::commodities.end() || + (*c).second->history || (*c).second->smaller || + (*c).second->larger) + throw new error(std::string("Failed to read base commodity from cache: ") + + commodity->symbol); + + (*c).second->name = commodity->name; + (*c).second->note = commodity->note; + (*c).second->precision = commodity->precision; + (*c).second->flags = commodity->flags; + (*c).second->history = commodity->history; + (*c).second->smaller = commodity->smaller; + (*c).second->larger = commodity->larger; + + *(base_commodities_next - 1) = (*c).second; + } } for (commodity_base_t::ident_t i = 0; i < bc_count; i++) @@ -655,9 +675,9 @@ unsigned int read_binary_journal(std::istream& in, std::pair result = commodity_t::commodities.insert(commodities_pair(mapping_key, commodity)); - if (! result.second) - throw error(std::string("Failed to read commodity from cache: ") + - commodity->ptr->symbol); + if (! result.second && commodity->annotated) + throw new error(std::string("Failed to read commodity from cache: ") + + commodity->ptr->symbol); } commodity_t::ident_t ident; -- cgit v1.2.3