<?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>26241</bug_id>
          
          <creation_ts>2014-06-30 16:56:26 +0000</creation_ts>
          <short_desc>Clarification request: What happens in FetchBodyStream on failure?</short_desc>
          <delta_ts>2014-08-12 13:15:41 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>Fetch</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WORKSFORME</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Josh Karlin">jkarlin</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>d</cc>
    
    <cc>mike</cc>
          
          <qa_contact>sideshowbarker+fetchspec</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>108503</commentid>
    <comment_count>0</comment_count>
    <who name="Josh Karlin">jkarlin</who>
    <bug_when>2014-06-30 16:56:26 +0000</bug_when>
    <thetext>What if there is an error while reading (algorithm step 4.3) the stream?  Should the Promise reject?  With what error?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108509</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-06-30 19:51:43 +0000</bug_when>
    <thetext>I&apos;m not sure in what ways reading a network IO stream can fail. On the response side I can see the network terminating (not harmful, should close the stream). On the request side there&apos;s no obvious failure case.

What am I missing?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108530</commentid>
    <comment_count>2</comment_count>
    <who name="Josh Karlin">jkarlin</who>
    <bug_when>2014-06-30 23:42:12 +0000</bug_when>
    <thetext>So if the network terminates early, the body will contain all of the bytes read up until termination?  Sounds good.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108534</commentid>
    <comment_count>3</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2014-07-01 00:12:33 +0000</bug_when>
    <thetext>Hmm. While that is certainly possible, I think it would make the most sense to reject the promise with an error... I don&apos;t think users would expect a half-response.

Or do I misunderstand, and is early network termination not really an error?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108538</commentid>
    <comment_count>4</comment_count>
    <who name="Josh Karlin">jkarlin</who>
    <bug_when>2014-07-01 01:51:35 +0000</bug_when>
    <thetext>You&apos;re right, if the response&apos;s type is error then the promise is rejected.  I missed that part in my first read.  All clear now, thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108549</commentid>
    <comment_count>5</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-01 06:23:30 +0000</bug_when>
    <thetext>Reopening since we&apos;re not on one line.

Comment 2 is accurate. We don&apos;t actively check Content-Length (some servers are bogus). There&apos;s also a flag set if the user, developer, or browser terminated the fetch for some reason. When that happens XMLHttpRequest currently clears the response. fetch() does nothing (as only the browser can currently terminate fetch() and that would be in a OOM or GC type of situation).

The promise that is rejected (comment 4) if response&apos;s type is error is fetch(), not fetch().then(r =&gt; r.body.asBlob()).

I think the current setup makes sense, you basically cannot fail once you got a successful batch of headers, but if you don&apos;t let me know.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108629</commentid>
    <comment_count>6</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2014-07-01 20:57:49 +0000</bug_when>
    <thetext>&gt; The promise that is rejected (comment 4) if response&apos;s type is error is fetch(), not fetch().then(r =&gt; r.body.asBlob()).

Notably if `fetch()` is rejected, then `r =&gt; r.body.asBlob()` will not run. In fact, you cannot get access to `r`, can you?

&gt; I think the current setup makes sense, you basically cannot fail once you got a successful batch of headers 

To clarify, what would happen for the less-&quot;raw&quot; asX() methods? E.g. for asJSON, what if:

- the body is `{ x: &quot;y&quot; }` (length 10) but the Content-Length header is 12
- the body is `{ x: &quot;y&quot; }` but the Content-Length header is 2</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>108638</commentid>
    <comment_count>7</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-02 09:27:34 +0000</bug_when>
    <thetext>Yes, the promise fetch() returns would be rejected with a TypeError so there is no Response object.

For the first case you would get {x:&quot;y&quot;} as return value. The actual body that is being parsed would be of length ten as at that point the connection would be closed. The second case would be a SyntaxError as per HTTP everything after &quot;{ &quot; would be ignored. (HTTP defines how to deal with Content-Length mismatch.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>109656</commentid>
    <comment_count>8</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-31 13:57:27 +0000</bug_when>
    <thetext>Is this clear now?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>109693</commentid>
    <comment_count>9</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2014-07-31 18:55:01 +0000</bug_when>
    <thetext>(In reply to Anne from comment #8)
&gt; Is this clear now?

yep, comment #7 sounds good. For people skimming the spec calling out those two scenarios explicitly (as non-normative examples) might be helpful, since you can imagine other behaviors, e.g. Content-Length mismatches causing rejection in the first case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>109733</commentid>
    <comment_count>10</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-08-01 05:55:26 +0000</bug_when>
    <thetext>Could you imagine that after reading HTTP? Unless we contradict HTTP I&apos;m not sure examples are warranted.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>110083</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-08-12 13:15:41 +0000</bug_when>
    <thetext>Leaving the examples to HTTP. Feel free to reopen if you disagree.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>