From e1fe9b45e0878682918bab472c02091c9f93e11d Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 2 Dec 2020 12:12:56 +0000 Subject: [PATCH] Unzip: adjust error reporting mechanism MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don’t use local exception throw+catch to report failures in extracting a zip archive, since this generates noise in Sentry. --- simgear/io/untar.cxx | 50 +++++++++++++++++++++++--------------------- simgear/io/untar.hxx | 5 +++++ 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/simgear/io/untar.cxx b/simgear/io/untar.cxx index 59da58f0..dc6e59b9 100644 --- a/simgear/io/untar.cxx +++ b/simgear/io/untar.cxx @@ -511,32 +511,34 @@ public: const size_t BUFFER_SIZE = 1024 * 1024; void* buf = malloc(BUFFER_SIZE); - try { - int result = unzGoToFirstFile(zip); - if (result != UNZ_OK) { - throw sg_exception("failed to go to first file in archive"); - } - - while (true) { - extractCurrentFile(zip, (char*)buf, BUFFER_SIZE); - if (state == FILTER_STOPPED) { - break; - } - - result = unzGoToNextFile(zip); - if (result == UNZ_END_OF_LIST_OF_FILE) { - break; - } - else if (result != UNZ_OK) { - throw sg_io_exception("failed to go to next file in the archive"); - } - } - state = END_OF_ARCHIVE; - } - catch (sg_exception&) { + int result = unzGoToFirstFile(zip); + if (result != UNZ_OK) { + SG_LOG(SG_IO, SG_ALERT, outer->rootPath() << "failed to go to first file in archive:" << result); state = BAD_ARCHIVE; + free(buf); + unzClose(zip); + return; } - + + while (true) { + extractCurrentFile(zip, (char*)buf, BUFFER_SIZE); + if (state == FILTER_STOPPED) { + state = END_OF_ARCHIVE; + break; + } + + result = unzGoToNextFile(zip); + if (result == UNZ_END_OF_LIST_OF_FILE) { + state = END_OF_ARCHIVE; + break; + } else if (result != UNZ_OK) { + SG_LOG(SG_IO, SG_ALERT, outer->rootPath() << "failed to go to next file in archive:" << result); + state = BAD_ARCHIVE; + break; + } + } + + free(buf); unzClose(zip); } diff --git a/simgear/io/untar.hxx b/simgear/io/untar.hxx index 9760544c..dd79e82d 100644 --- a/simgear/io/untar.hxx +++ b/simgear/io/untar.hxx @@ -70,6 +70,11 @@ public: Stop }; + SGPath rootPath() const + { + return _rootPath; + } + protected: