Changeset 556

Show
Ignore:
Timestamp:
2007-08-07 22:49:32 (1 year ago)
Author:
MaierMan
Message:

fixing #297: "soft"-fail for a range of errors we can possibly recover from (like timeouts)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/chrome/content/dta/manager.js

    r551 r556  
    4343        var Ci = Components.interfaces; 
    4444} 
     45if (!Exception) { 
     46        var Exception = Components.Exception; 
     47} 
    4548 
    4649const MIN_CHUNK_SIZE = 700 * 1024; 
     
    622625                                } 
    623626                                Debug.dump(x + " missing"); 
    624                                 throw new Components.Exception(x + " is missing"); 
     627                                throw new Exception(x + " is missing"); 
    625628                        } 
    626629                        // header is there, but differs 
    627630                        else if (this[x] != v[x]) { 
    628631                                Debug.dump(x + " nm: [" + this[x] + "] [" + v[x] + "]"); 
    629                                 throw new Components.Exception("Header " + x + " doesn't match"); 
     632                                throw new Exception("Header " + x + " doesn't match"); 
    630633                        } 
    631634                } 
     
    713716                        } 
    714717                } 
    715                 throw new Components.Exception("No Date registered"); 
     718                throw new Exception("No Date registered"); 
    716719        } 
    717720}; 
     
    11231126                                // small validation. Around epoche? More than a month in future? 
    11241127                                if (time < 2 || time > Date.now() + 30 * 86400000) { 
    1125                                         throw new Components.Exception("invalid date encountered: " + time + ", will not set it"); 
     1128                                        throw new Exception("invalid date encountered: " + time + ", will not set it"); 
    11261129                                } 
    11271130                                // have to unwrap 
     
    14541457} 
    14551458 
    1456 var Chunk = function(download, start, end, written) { 
     1459function Chunk(download, start, end, written) { 
    14571460        // saveguard against null or strings and such 
    14581461        this._written = written > 0 ? written : 0; 
     
    14611464        this.end = end; 
    14621465        this._parent = download; 
     1466        this._sessionbytes = 0; 
    14631467} 
    14641468 
     
    15041508        }, 
    15051509        open: function CH_open() { 
     1510                this._sessionBytes = 0; 
    15061511                let file = this.parent.tmpFile.clone(); 
    15071512                if (!file.parent.exists()) { 
     
    15351540                } 
    15361541        }, 
     1542        rollback: function CH_rollback() { 
     1543                if (!this._sessionBytes || this._sessionBytes > this._written) { 
     1544                        return; 
     1545                } 
     1546                this._written -= this._sessionBytes; 
     1547                this._sessionBytes = 0; 
     1548        }, 
    15371549        cancel: function CH_cancel() { 
    15381550                this.running = false; 
     
    15571569                        } 
    15581570                        if (bytes < 0) { 
    1559                                 throw new Components.Exception("bytes negative"); 
     1571                                throw new Exception("bytes negative"); 
    15601572                        } 
    15611573                        // we're using nsIFileOutputStream 
     
    15641576                        } 
    15651577                        this._written += bytes; 
     1578                        this._sessionBytes += bytes; 
    15661579 
    15671580                        this.parent.timeLastProgress = Utils.getTimestamp(); 
    15681581 
    15691582                        return bytes; 
    1570                 } catch (ex) { 
     1583                } 
     1584                catch (ex) { 
    15711585                        Debug.dump('write: ' + this.parent.tmpFile.path, ex); 
    15721586                        throw ex; 
     
    17951809                        d.chunks[found].end = c.end; 
    17961810                        if (--d.maxChunks == 1) { 
    1797                                 d.resumable = false; 
     1811                                //d.resumable = false; 
    17981812                        } 
    17991813                        d.chunks = d.chunks.filter(function(ch) { return ch != c; }); 
     
    18401854                } 
    18411855                  
    1842                  
    18431856                if (code >= 400) { 
    18441857                        if (!this.handleError()) { 
    18451858                                Debug.dump("handleError: Cannot recover from problem!", code); 
    1846                                 var file = d.fileName.length > 50 ? d.fileName.substring(0, 50) + "..." : d.fileName; 
    1847                                 code = Utils.formatNumber(code, 3); 
    1848                                 d.fail( 
    1849                                         _("error", [code]), 
    1850                                         _("failed", [file]) + " " + _("sra", [code]) + ": " + status, 
    1851                                         _("error", [code]) 
    1852                                 ); 
     1859                                if ([401, 402, 407, 500, 502, 503, 504].indexOf(code) != -1) { 
     1860                                        Debug.dump("we got temp failure!", code); 
     1861                                        d.pause(); 
     1862                                        d.status = code >= 500 ? _('temperror') : _('autherror'); 
     1863                                } 
     1864                                else { 
     1865                                        var file = d.fileName.length > 50 ? d.fileName.substring(0, 50) + "..." : d.fileName; 
     1866                                        code = Utils.formatNumber(code, 3); 
     1867                                        d.fail( 
     1868                                                _("error", [code]), 
     1869                                                _("failed", [file]) + " " + _("sra", [code]) + ": " + status, 
     1870                                                _("error", [code]) 
     1871                                        ); 
     1872                                } 
     1873                                // any data that we got over this channel should be considered "corrupt" 
     1874                                c.rollback(); 
    18531875                                SessionManager.save(d); 
    18541876                        } 
     
    19521974                // hack: determine if we are a multi-part chunk, 
    19531975                // if so something bad happened, 'cause we aren't supposed to be multi-part 
    1954                 if (c.start != 0) { 
     1976                if (c.start != 0 && d.is(RUNNING)) { 
    19551977                        if (!this.handleError()) { 
    19561978                                Debug.dump(d + ": Server error or disconnection (type 1)"); 
     
    21142136                 
    21152137                // rude way to determine disconnection: if connection is closed before download is started we assume a server error/disconnection 
    2116                 if (c.starter && !shouldFinish) { 
     2138                if (c.starter && !shouldFinish && d.is(RUNNING)) { 
    21172139                        if (!d.urlManager.markBad(this.url)) { 
    2118                                 Debug.dump(d + ": Server error or disconnection (type 1)"); 
     2140                                Debug.dump(d + ": Server error or disconnection (type 2)"); 
    21192141                                d.status = _("servererror"); 
    21202142                                d.speed = ''; 
  • trunk/chrome/locale/en-US/manager.properties

    r537 r556  
    2121failed=Failed 
    2222servererror=Server error 
     23autherror=Authentication failed  
     24temperror=Temporary error 
    2325sra=Server returned a %S error 
    2426errmismatchtitle=Size mismatch