From 75c7c8a218ad9b2024b89ca5c6bdf0540c1dc383 Mon Sep 17 00:00:00 2001 From: mossroy Date: Tue, 1 Apr 2014 11:40:23 +0200 Subject: [PATCH] It happens that bzip2 decompression fails with "No magic number found". It's known bug, not yet solved. When this happens, we should not ask the user to report it, but instead invite him to see the corresponding issue on Github. Fixes #77 + slightly improve the way we report other decompression errors to the user --- www/js/app.js | 1 + www/js/lib/archive.js | 95 +++++++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index de555262..d00595b2 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -499,6 +499,7 @@ define(function(require) { /** * Display the the given HTML article in the web page, * and convert links to javascript calls + * NB : in some error cases, the given title can be null, and the htmlArticle contains the error message * @param {type} title * @param {type} htmlArticle */ diff --git a/www/js/lib/archive.js b/www/js/lib/archive.js index 3fb8573a..e05070cd 100644 --- a/www/js/lib/archive.js +++ b/www/js/lib/archive.js @@ -473,54 +473,53 @@ define(function(require) { alert('Data file read cancelled'); }; reader.onload = function(e) { - try { - var compressedArticles = e.target.result; - webworkerBzip2.onerror = function(event){ - // TODO can probably be replaced by some error handler at window level - alert("An unexpected error occured during bzip2 decompression. Please report it to us by email or through Github (see About section), with the names of the archive and article, and the following info : message=" - + event.message + " filename=" + event.filename + " line number=" + event.lineno ); - throw new Error("Error during bzip2 decompression : " + event.message + " (" + event.filename + ":" + event.lineno + ")"); - }; - webworkerBzip2.onmessage = function(event){ - switch (event.data.cmd){ - case "result": - var htmlArticles = event.data.msg; - // Start reading at offset, and keep length characters - var htmlArticle = htmlArticles.substring(title._blockOffset, - title._blockOffset + title._articleLength); - if (htmlArticle.length >= title._articleLength) { - // Keep only length characters - htmlArticle = htmlArticle.substring(0, title._articleLength); - // Decode UTF-8 encoding - htmlArticle = decodeURIComponent(escape(htmlArticle)); - callbackFunction(title, htmlArticle); - } else { - // TODO : throw exception if we reach the end of the file - currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE, - callbackFunction); - } - break; - case "recurse": - currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE, callbackFunction); - break; - case "debug": - console.log(event.data.msg); - break; - case "error": - // TODO can probably be replaced by some error handler at window level - alert("An unexpected error occured during bzip2 decompression. Please report it to us by email or through Github (see About section), with the names of the archive and article, and the following info : message=" - + event.data.msg ); - throw new Error("Error during bzip2 decompression : " + event.data.msg); - break; - } - }; - webworkerBzip2.postMessage({cmd : 'uncompress', msg : - new Uint8Array(compressedArticles)}); - - } - catch (e) { - callbackFunction("Error : " + e); - } + var compressedArticles = e.target.result; + webworkerBzip2.onerror = function(event){ + // TODO can probably be replaced by some error handler at window level + callbackFunction(null, "An unexpected error occured during bzip2 decompression. Please report it to us by email or through Github (see About section), with the names of the archive and article, and the following info : message=" + + event.message + " filename=" + event.filename + " line number=" + event.lineno); + }; + webworkerBzip2.onmessage = function(event){ + switch (event.data.cmd){ + case "result": + var htmlArticles = event.data.msg; + // Start reading at offset, and keep length characters + var htmlArticle = htmlArticles.substring(title._blockOffset, + title._blockOffset + title._articleLength); + if (htmlArticle.length >= title._articleLength) { + // Keep only length characters + htmlArticle = htmlArticle.substring(0, title._articleLength); + // Decode UTF-8 encoding + htmlArticle = decodeURIComponent(escape(htmlArticle)); + callbackFunction(title, htmlArticle); + } else { + // TODO : throw exception if we reach the end of the file + currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE, + callbackFunction); + } + break; + case "recurse": + currentLocalArchiveInstance.readArticleChunk(title, dataFile, reader, readLength + CHUNK_SIZE, callbackFunction); + break; + case "debug": + console.log(event.data.msg); + break; + case "error": + // TODO can probably be replaced by some error handler at window level + if (event.data.msg === "No magic number found") { + // See https://github.com/mossroy/evopedia-html5/issues/77 + // It's a temporary workaround until https://github.com/mossroy/evopedia-html5/issues/6 is fixed + callbackFunction(null, "Oops : this article can not be displayed for now. It's a known bug that is not solved yet. See issue #6 on Github for more info"); + } + else { + callbackFunction(null, "An unexpected error occured during bzip2 decompression. Please report it to us by email or through Github (see About section), with the names of the archive and article, and the following info : message=" + + event.data.msg); + } + break; + } + }; + webworkerBzip2.postMessage({cmd : 'uncompress', msg : + new Uint8Array(compressedArticles)}); }; var blob = dataFile.slice(title._blockStart, title._blockStart + readLength);