David and Justin,

Thanks for your further thoughts on this. I've since had some clarity about
what I'll recommend. We have middle-tier code that is (or should be)
responsible for ensuring that all the required parameters are present
before querying MarkLogic, so cluttering the error log should not be an
issue if that part is behaving correctly. Instead, it should be quite
exceptional and alert us to a problem in our code elsewhere. For us then,
the parameter validation on the XQuery side is more analogous to an
"assert" statement (or XQuery type declaration or "treat as" expression).
"This should never happen, so if it does, then blow up immediately."

Thanks again for your reflections!
Evan

On Wed, Jan 24, 2018 at 11:27 PM, Justin Makeig <justin.mak...@marklogic.com
> wrote:

> If not, we will probably need to restructure the queries to not throw an
> XQuery error at all and just send the appropriate response code and error
> message. Darn, oh well.
>
>
> As the docs for fn:error() say, the expected behavior when throwing an
> error is to stop the execution, rollback any inflight transactions, and
> immediately return. try/catch can capture (most) errors, but parameter
> validation sounds more like regular program flow than a fatal error
> condition. Given the documented behavior of thrown errors, I’d assert the
> logging to the error log is the correct and expected default behavior. Is
> there a way you could refactor to not throw errors, but return something
> like a boolean or a status code (that you could translate to an HTTP status
> code on the way out)?
>
> Justin
>
>
> On Jan 24, 2018, at 10:54 PM, David Ennis <david.en...@marklogic.com>
> wrote:
>
> HI Evan,
>
> Hmm. I just did the same test and was surprised. But yes, still logging
> the error seems to match the documentation.. Sorry about that. My only
> other suggestion is: Is there any common code used as some sort of standard
> invoker/router to the rest of your code? If so, that may be the best place
> to put a tray catch and let the rest bubble up to that point.
>
> Regards,
> David
>
> --
>
>
> *From: *<general-boun...@developer.marklogic.com> on behalf of Evan Lenz <
> e...@evanlenz.net>
> *Reply-To: *MarkLogic Developer Discussion <general@developer.marklogic.
> com>
> *Date: *Thursday, January 25, 2018 at 1:43 AM
> *To: *MarkLogic Developer Discussion <general@developer.marklogic.com>
> *Subject: *Re: [MarkLogic Dev General] Exit query without writing to
> error log?
>
> Hi David,
>
> Following up on this. I tried the custom error handler, and it appears
> that the errors are not actually caught but just forwarded to the
> error-handler XQuery. The impact of this for me (and which is what I'm
> trying to address) is that the errors are still written to the error log,
> regardless of whether they are handled by a custom error handler. Does this
> accord with your understanding of how it's supposed to work?
>
> Do you have any other ideas for how to prevent the writing to the error
> log? If not, we will probably need to restructure the queries to not throw
> an XQuery error at all and just send the appropriate response code and
> error message. Darn, oh well.
>
> Thanks,
> Evan
>
> On Wed, Jan 24, 2018 at 2:45 PM, Evan Lenz <e...@evanlenz.net> wrote:
>
> Thanks, guys. David, the custom error handler is a great idea. I had
> forgotten about this option. We're not currently using it but definitely
> will soon. It will help us move forward without fundamentally changing the
> structure of many queries. It will enable us to wrap a virtual try/catch
> around everything without having to change the code itself. Very helpful!
>
> Thanks again,
> Evan
>
>
> On Wed, Jan 24, 2018 at 4:57 AM, David Ennis <david.en...@marklogic.com>
> wrote:
>
> HI.
>
> Further to Florent’s comment, assuming your code is OK with the error
> bubbling up to the top, you can catch them all in a single place and act
> accordingly  using a custom error handler. Using this in conjunction with
> throwing your own errors (and handling the code in the top-level handler)
> can be useful.
>
> https://docs.marklogic.com/guide/app-dev/appserver-control#id_89735
>
> Regards,
> David
>
> --
>
>
> *From: *<general-boun...@developer.marklogic.com> on behalf of Florent
> Georges <li...@fgeorges.org>
> *Reply-To: *MarkLogic Developer Discussion <general@developer.marklogic.
> com>
> *Date: *Wednesday, January 24, 2018 at 1:53 PM
> *To: *MarkLogic Developer Discussion <general@developer.marklogic.com>
> *Subject: *Re: [MarkLogic Dev General] Exit query without writing to
> error log?
>
> Hi Evan,
>
> The error is logged only if it "reaches the top", that is, if it is not
> caught.
>
> If the error shouldn't behave as such, can't you just catch it before?
> (and yes, potentially return wathever HTTP response you deem appropriate).
>
> Regards,
>
> --
> Florent Georges
> H2O Consulting
> http://h2o.consulting/
>
>
> On 24 January 2018 at 03:22, Evan Lenz wrote:
>
> Hello,
>
> My client has XQuery parameter-validation code which calls the error()
> function when invalid parameters are supplied. This event gets written to
> the error log. Is there a way to prevent this?
>
> I recognize the best practice is to return a more appropriate HTTP
> response code (than 500) when handling invalid input. I also recognize this
> is anathema to FP. But my question still stands:
>
> Is there a way to interrupt/exit a query without triggering an Error-level
> log message?
>
> Thanks,
>
> Evan Lenz
> President, Lenz Consulting Group, Inc.
> http://lenzconsulting.com
>
>
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
>
>
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
>
>
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
>
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to