Skip to content

Commit

Permalink
#810 Handle libzip error
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitri Baron <[email protected]>
  • Loading branch information
barondim committed Jan 9, 2025
1 parent 1826950 commit efc0b5b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions sources/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ configure_file(${CMAKE_SOURCE_DIR}/cmake/version.h.in ${CMAKE_CURRENT_SOURCE_DIR
set(SOURCES
src/Options.cpp
src/Log.cpp
src/ZipErrorMessage.cpp
src/DFLLog_keys.cpp
src/DFLError_keys.cpp
)
Expand Down
15 changes: 15 additions & 0 deletions sources/Common/include/ZipErrorMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Copyright (c) 2025, RTE (http://www.rte-france.com)
// See AUTHORS.txt
// All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0
//

#pragma once

#include <libzip/ZipException.h>

std::string formatZipErrorMessage(const zip::ZipException& e);
10 changes: 8 additions & 2 deletions sources/Common/src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
*/

#include "Options.h"

#include "ZipErrorMessage.h"
#include "version.h"

#include <libzip/ZipInputStream.h>
#include <libzip/ZipException.h>
#include <boost/filesystem.hpp>

#include <DYNFileSystemUtils.h>

#include <algorithm>
#include <boost/filesystem.hpp>
#include <sstream>


namespace dfl {
namespace common {

Expand Down Expand Up @@ -147,6 +149,10 @@ Options::parse(int argc, char* argv[]) {
} else {
return Request::RUN_SIMULATION_N;
}
} catch (const zip::ZipException& e) {
std::string zipErrorMessage = formatZipErrorMessage(e);
std::cerr << zipErrorMessage << std::endl;
return Request::ERROR;
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return Request::ERROR;
Expand Down
33 changes: 33 additions & 0 deletions sources/Common/src/ZipErrorMessage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Copyright (c) 2025, RTE (http://www.rte-france.com)
// See AUTHORS.txt
// All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0
//

#include "ZipErrorMessage.h"

#include <sstream>


std::string formatZipErrorMessage(const zip::ZipException& e) {
std::stringstream zipErrorStream;
switch (e.getErrorCode()) {
case zip::Error::Code::LIBARCHIVE_INTERNAL_ERROR:
zipErrorStream << "Libarchive internal error";
break;
case zip::Error::Code::FILE_NOT_FOUND:
zipErrorStream << "File " << e.what() << " not found";
break;
case zip::Error::Code::CANNOT_OPEN_FILE:
zipErrorStream << "File " << e.what() << " cannot be opened";
break;
default:
zipErrorStream << "Libzip unknown error";
break;
}
return zipErrorStream.str();
}

0 comments on commit efc0b5b

Please sign in to comment.