diff options
author | John Wiegley <johnw@newartisans.com> | 2009-10-31 03:34:32 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-10-31 04:07:33 -0400 |
commit | 4427016b1bc20fac4c1700e4f1577f6c7f9ab78c (patch) | |
tree | 26ad49d11ee95667aea74e3513b168c864a569c0 /src/item.cc | |
parent | 77c9d7b1ff9fc0033e653453e08d042b2e95692b (diff) | |
download | fork-ledger-4427016b1bc20fac4c1700e4f1577f6c7f9ab78c.tar.gz fork-ledger-4427016b1bc20fac4c1700e4f1577f6c7f9ab78c.tar.bz2 fork-ledger-4427016b1bc20fac4c1700e4f1577f6c7f9ab78c.zip |
Improved arg checking for several valexpr functions
Diffstat (limited to 'src/item.cc')
-rw-r--r-- | src/item.cc | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/item.cc b/src/item.cc index 631423a9..debda7a3 100644 --- a/src/item.cc +++ b/src/item.cc @@ -32,6 +32,7 @@ #include <system.hh> #include "item.h" +#include "interactive.h" namespace ledger { @@ -210,15 +211,31 @@ namespace { return item.has_tag(args[0].as_string()); else if (args[0].is_mask()) return item.has_tag(args[0].as_mask()); - } else { - return item.has_tag(args[0].to_mask(), args[1].to_mask()); + else + throw_(std::logic_error, + _("Expected string for argument 1, but received %1") + << args[0].label()); + } + else if (args.size() == 2) { + if (args[0].is_mask() && args[1].is_mask()) + return item.has_tag(args[0].to_mask(), args[1].to_mask()); + else + throw_(std::logic_error, + _("Expected masks for arguments 1 and 2, but received %1 and %2") + << args[0].label() << args[1].label()); + } + else if (args.size() == 0) { + throw_(std::logic_error, _("Too few arguments to function")); + } + else { + throw_(std::logic_error, _("Too many arguments to function")); } return false; } - value_t get_tag(call_scope_t& args) { - item_t& item(find_scope<item_t>(args)); - if (optional<string> value = item.get_tag(args[0].as_string())) + value_t get_tag(call_scope_t& scope) { + in_context_t<item_t> env(scope, "s"); + if (optional<string> value = env->get_tag(env.get<string>(0))) return string_value(*value); return false; } |