Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Commit

Permalink
json2pub function that can fail louder
Browse files Browse the repository at this point in the history
  • Loading branch information
egwynn committed Mar 27, 2014
1 parent 327878e commit 03a0cc7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions librfn/dict.C
Expand Up @@ -95,10 +95,26 @@ namespace rfn3 {
ptr<const expr_t>
json2pub_t::v_eval_2 (eval_t *p, const vec<arg_t> &args) const
{
str s = args[0]._s;
ptr<expr_t> ret;
ret = json_parser_t::parse (s);
return ret;
str s = args[0]._s;
bool verbose = false;
if (args.size() > 1) verbose = args[1]._b;

if (verbose) {
ptr<json_parser_t> parser = New refcounted<json_parser_t> ();
ptr<expr_t> ret = parser->mparse (s);
if (!ret || ret->is_null()) {
str err = str("Invalid JSON: ") << s << "\n";
for (auto& e: parser->get_errors())
err = err << e << "\n";
report_error (p, err);
}
return ret;
}
else {
ptr<expr_t> ret;
ret = json_parser_t::parse (s);
return ret;
}
}

//-----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion librfn/okrfn-int.h
Expand Up @@ -31,7 +31,7 @@ namespace rfn3 {
PUB3_COMPILED_FN_DOC(keys, "d");
PUB3_COMPILED_FN_DOC(items, "d");
PUB3_COMPILED_FN(remove, "ds");
PUB3_COMPILED_FN_DOC(json2pub, "s");
PUB3_COMPILED_FN_DOC(json2pub, "s|b");
PUB3_COMPILED_FN_DOC(cgi2pub, "s");
PUB3_COMPILED_FN_DOC(now, "");
PUB3_COMPILED_FN_DOC(time_format, "us");
Expand Down

0 comments on commit 03a0cc7

Please sign in to comment.