<div dir="ltr">For aeson there is a <?> combinator in an "internal" modue lfor adding custom error messages (<a href="https://github.com/bos/aeson/issues/475">https://github.com/bos/aeson/issues/475</a>). There's definitely room for improving error messages though, I hope you'd consider helping out with that in aeson rather than rolling your own :)<div><br></div><div>But what Michael says makes a lot of sense, going through aeson is not optimal. Especially since yaml is a superset (in terms of constructs) of json.</div><div><br></div><div>- Adam</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Nov 3, 2016 at 10:55 AM Michael Snoyman <<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">The Text.Libyaml[1] module provides a streaming interface, which allows more flexibility and doesn't jump through the aeson Value type at all. Currently, it doesn't include location information, but I _think_ the underlying libyaml C library makes that information available. I'd certainly be open to a PR to add something like:<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">decodeWithPosition :: ByteString -> Producer m (Event, Position)</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">And that way you don't have to rewrite a parser or the FFI bindings.<br class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">[1] <a href="https://www.stackage.org/haddock/lts-7.7/yaml-0.8.20/Text-Libyaml.html" class="gmail_msg" target="_blank">https://www.stackage.org/haddock/lts-7.7/yaml-0.8.20/Text-Libyaml.html</a></div></div></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Thu, Nov 3, 2016 at 11:47 AM, Tobias Dammers <span dir="ltr" class="gmail_msg"><<a href="mailto:tdammers@gmail.com" class="gmail_msg" target="_blank">tdammers@gmail.com</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello cafe,<br class="gmail_msg">
<br class="gmail_msg">
I have a bit of a conundrum here.<br class="gmail_msg">
<br class="gmail_msg">
The situation is such that I'm using the YAML package to parse YAML<br class="gmail_msg">
configuration files; some of the values in the file format require<br class="gmail_msg">
further parsing (using my own ginger library), and all that works fine.<br class="gmail_msg">
<br class="gmail_msg">
One problem though; since this is aimed at end users, I want to preset<br class="gmail_msg">
error messages that pinpoint the exact error location in case the ginger<br class="gmail_msg">
parse fails. However, the ginger parser doesn't get to see the entire<br class="gmail_msg">
YAML source, because it runs on just an individual string value inside<br class="gmail_msg">
the YAML, and the YAML parser itself doesn't report source positions<br class="gmail_msg">
either. The unfortunate result is that while I get "technically correct"<br class="gmail_msg">
parser errors from Ginger, the source positions they report are relative<br class="gmail_msg">
to the string value, i.e., all errors are reported as being on line 1 of<br class="gmail_msg">
an unnamed source file.<br class="gmail_msg">
<br class="gmail_msg">
The relevant code is here:<br class="gmail_msg">
<br class="gmail_msg">
<a href="https://github.com/tdammers/sprinkles/blob/master/src/Web/Sprinkles/Replacement.hs#L40" rel="noreferrer" class="gmail_msg" target="_blank">https://github.com/tdammers/sprinkles/blob/master/src/Web/Sprinkles/Replacement.hs#L40</a><br class="gmail_msg">
<br class="gmail_msg">
The only solution I can think of right now involves writing my own YAML<br class="gmail_msg">
parser, and probably also an Aeson drop-in replacement; I don't really<br class="gmail_msg">
want to do that though.<br class="gmail_msg">
<br class="gmail_msg">
Is there any other way to get what I want?<br class="gmail_msg">
<span class="m_5195135685274578344HOEnZb gmail_msg"><font color="#888888" class="gmail_msg"><br class="gmail_msg">
--<br class="gmail_msg">
Tobias Dammers - <a href="mailto:tdammers@gmail.com" class="gmail_msg" target="_blank">tdammers@gmail.com</a><br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Haskell-Cafe mailing list<br class="gmail_msg">
To (un)subscribe, modify options or view archives go to:<br class="gmail_msg">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br class="gmail_msg">
Only members subscribed via the mailman list are allowed to post.</font></span></blockquote></div><br class="gmail_msg"></div>
_______________________________________________<br class="gmail_msg">
Haskell-Cafe mailing list<br class="gmail_msg">
To (un)subscribe, modify options or view archives go to:<br class="gmail_msg">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br class="gmail_msg">
Only members subscribed via the mailman list are allowed to post.</blockquote></div>