Improved some error messages

This commit is contained in:
John Wiegley 2012-03-29 16:25:22 -05:00
parent 7422fa5f3e
commit 0f180b917a
4 changed files with 20 additions and 13 deletions

View file

@ -398,8 +398,8 @@ int amount_t::compare(const amount_t& amt) const
if (has_commodity() && amt.has_commodity() && if (has_commodity() && amt.has_commodity() &&
commodity() != amt.commodity()) commodity() != amt.commodity())
throw_(amount_error, throw_(amount_error,
_("Cannot compare amounts with different commodities: %1 and %2") _("Cannot compare amounts with different commodities: '%1' and '%2'")
<< commodity().symbol() << amt.commodity().symbol()); << commodity() << amt.commodity());
return mpq_cmp(MP(quantity), MP(amt.quantity)); return mpq_cmp(MP(quantity), MP(amt.quantity));
} }
@ -430,12 +430,11 @@ amount_t& amount_t::operator+=(const amount_t& amt)
throw_(amount_error, _("Cannot add two uninitialized amounts")); throw_(amount_error, _("Cannot add two uninitialized amounts"));
} }
if (has_commodity() && amt.has_commodity() && if (has_commodity() && amt.has_commodity() && commodity() != amt.commodity()) {
commodity() != amt.commodity())
throw_(amount_error, throw_(amount_error,
_("Adding amounts with different commodities: %1 != %2") _("Adding amounts with different commodities: '%1' != '%2'")
<< (has_commodity() ? commodity().symbol() : _("NONE")) << commodity() << amt.commodity());
<< (amt.has_commodity() ? amt.commodity().symbol() : _("NONE"))); }
_dup(); _dup();
@ -464,9 +463,8 @@ amount_t& amount_t::operator-=(const amount_t& amt)
if (has_commodity() && amt.has_commodity() && if (has_commodity() && amt.has_commodity() &&
commodity() != amt.commodity()) commodity() != amt.commodity())
throw_(amount_error, throw_(amount_error,
_("Subtracting amounts with different commodities: %1 != %2") _("Subtracting amounts with different commodities: '%1' != '%2'")
<< (has_commodity() ? commodity().symbol() : _("NONE")) << commodity() << amt.commodity());
<< (amt.has_commodity() ? amt.commodity().symbol() : _("NONE")));
_dup(); _dup();

View file

@ -262,6 +262,14 @@ public:
const datetime_t& oldest = datetime_t()) const; const datetime_t& oldest = datetime_t()) const;
virtual commodity_t& strip_annotations(const keep_details_t& what_to_keep); virtual commodity_t& strip_annotations(const keep_details_t& what_to_keep);
virtual void print(std::ostream& out, bool elide_quotes = false,
bool print_annotations = false) const {
commodity_t::print(out, elide_quotes);
if (print_annotations)
write_annotations(out);
}
virtual void write_annotations(std::ostream& out, virtual void write_annotations(std::ostream& out,
bool no_computed_annotations = false) const; bool no_computed_annotations = false) const;

View file

@ -384,7 +384,7 @@ void commodity_t::parse_symbol(char *& p, string& symbol)
throw_(amount_error, _("Failed to parse commodity")); throw_(amount_error, _("Failed to parse commodity"));
} }
void commodity_t::print(std::ostream& out, bool elide_quotes) const void commodity_t::print(std::ostream& out, bool elide_quotes, bool) const
{ {
string sym = symbol(); string sym = symbol();
if (elide_quotes && has_flags(COMMODITY_STYLE_SEPARATED) && if (elide_quotes && has_flags(COMMODITY_STYLE_SEPARATED) &&

View file

@ -303,7 +303,8 @@ public:
return temp; return temp;
} }
void print(std::ostream& out, bool elide_quotes = false) const; virtual void print(std::ostream& out, bool elide_quotes = false,
bool print_annotations = false) const;
bool valid() const; bool valid() const;
struct compare_by_commodity { struct compare_by_commodity {
@ -338,7 +339,7 @@ private:
}; };
inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) { inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) {
comm.print(out); comm.print(out, false, true);
return out; return out;
} }