-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid param "not an object" when using {{#tests}} on a non-object #37
Comments
Niols
added a commit
to Niols/ocaml-mustache
that referenced
this issue
Dec 14, 2018
Yeah, that seems reasonable to me. |
Hey, is there any way to have the fix in a new opam release? Should I make a PR (with the fix from @Niols fork)? Thanks! |
Yes, that would be welcome. |
tsileo
added a commit
to tsileo/ocaml-mustache
that referenced
this issue
May 8, 2019
I hit this issue independently and proposed a fix in #49. My proposal is more invasive, but it more clearly corresponds to the specification, and there is no regression in existing tests. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I was trying to use Mustache to render a string only when it is non-null. This should essentially be the following template:
It works as expected with the Ruby implementation of Mustache in both cases. It does not however work with the OCaml implementation in the case where
key
exists. I getMustache_types.Invalid_param("str. not an object")
.My guess is that Mustache is happy with the test
{{#key}}
and puts the JSON forkey
in the context. When later rendering{{key}}
it fails because the context is not an object. It's actually a bit more than a guess:In
render_fmt
, when rendering sections, we have:ocaml-mustache/lib/mustache.ml
Line 324 in 0333e46
where
add_context
is:ocaml-mustache/lib/mustache.ml
Lines 268 to 272 in 0333e46
which means that when
ctx
is not an object, the context becomes this non-object. And when we try to render something afterwards, we have a failure. I would rather have something like:Does that seem reasonable to you?
The text was updated successfully, but these errors were encountered: