<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>29758</bug_id>
          
          <creation_ts>2016-07-28 10:50:31 +0000</creation_ts>
          <short_desc>[FO31] What is the sort order of errors?</short_desc>
          <delta_ts>2016-12-16 19:55:25 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>Functions and Operators 3.1</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Abel Braaksma">abel.braaksma</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>127068</commentid>
    <comment_count>0</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-07-28 10:50:31 +0000</bug_when>
    <thetext>Going over the function array:sort, the second argument takes a higher order function. Such function could return an error. I wonder what is supposed to happen then.

Under &quot;Error conditions&quot; there is no mention that array:sort fails if this function returns an error.

Does this mean that if the second arg function returns an error, that such error should be ignored, and if so, it is sortable? Or can I deduct and say &quot;it is not comparable using the le operator&quot;, so the mentioned dynamic error (no specific error code is given) applies?

In the latter case it becomes a matter of definition: does the function raise an error and does that error bubble up, or does array:sort return (some) implementation-dependent error as mentioned in this section?

I think I would prefer to add a line to &quot;Error conditions&quot;. Something like:

&quot;If evaluation of $key results in an error being raised, the function array:sort fails with that error.&quot;

Example (contrived):

array:sort($arr, function($val) { fn:error(&quot;e:MYERR&quot;, &quot;Some error&quot;) } )</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127069</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-07-28 11:52:15 +0000</bug_when>
    <thetext>I thought it was obvious, and is surely stated somewhere, that an expression fails with a dynamic error if evaluation of one of its operands fails with a dynamic error.

But perhaps we need a general statement at the start of section 16 (higher-order functions). Certainly fn:sort is no different to any other higher-order function in this respect.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127304</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-09-06 15:36:27 +0000</bug_when>
    <thetext>Agreed we should add a note relevant to all higher-order functions that errors thrown by the called function are propagated</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127313</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-09-06 19:55:07 +0000</bug_when>
    <thetext>I have added a note to the intro of &quot;basic higher-order functions&quot; explaining that errors invoked when calling the caller-supplied function are propagated.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>