diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-10 21:32:31 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-10 21:32:38 -0600 |
commit | 02225a014a6e7b3d41cd6b64632b2dba06681c67 (patch) | |
tree | 0344f8f49749692100dfe76af2df5772e04dc21d /src | |
parent | 080c1d9a2d0f3013a4d26879a3e98cfa62ef3e48 (diff) | |
download | fork-ledger-02225a014a6e7b3d41cd6b64632b2dba06681c67.tar.gz fork-ledger-02225a014a6e7b3d41cd6b64632b2dba06681c67.tar.bz2 fork-ledger-02225a014a6e7b3d41cd6b64632b2dba06681c67.zip |
Give a better error when sequences are mis-indexed
Diffstat (limited to 'src')
-rw-r--r-- | src/report.cc | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/report.cc b/src/report.cc index c959e70a..4dd0bca4 100644 --- a/src/report.cc +++ b/src/report.cc @@ -539,13 +539,20 @@ value_t report_t::fn_get_at(call_scope_t& args) if (index == 0) { if (! args[0].is_sequence()) return args[0]; - } else { - if (! args[0].is_sequence()) - throw_(std::runtime_error, - _("Attempting to get argument at index %1 from %2") - << index << args[0].label()); } - return args[0].as_sequence()[index]; + else if (! args[0].is_sequence()) { + throw_(std::runtime_error, + _("Attempting to get argument at index %1 from %2") + << index << args[0].label()); + } + + value_t::sequence_t& seq(args[0].as_sequence_lval()); + if (index >= seq.size()) + throw_(std::runtime_error, + _("Attempting to get index %1 from %2 with %3 elements") + << index << args[0].label() << seq.size()); + + return seq[index]; } value_t report_t::fn_is_seq(call_scope_t& scope) |