Skip to content

Commit

Permalink
Move stream exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Werni2A committed Dec 30, 2023
1 parent 91db9e2 commit 1231f86
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
26 changes: 1 addition & 25 deletions src/Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <thread>
#include <vector>

#include <fmt/color.h>
#include <fmt/core.h>
#include <spdlog/spdlog.h>

Expand Down Expand Up @@ -96,7 +95,7 @@ void Container::parseLibraryThread(std::vector<std::unique_ptr<Stream>*> aStream
catch(...)
{
parsedSuccessfully = false;
exceptionHandling();
(*stream)->exceptionHandling();
}

(*stream)->mCtx.mParsedSuccessfully = parsedSuccessfully;
Expand Down Expand Up @@ -204,29 +203,6 @@ void Container::parseLibrary()
}


void Container::exceptionHandling()
{
try
{
throw;
}
catch(const std::exception& e)
{
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "--------ERROR REPORT--------"));
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "Input Container: {}", mCtx.mInputCfbfFile.string()));
// @todo
// mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "Current File: {}", mCtx.mInputStream.string()));
// mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), mCtx.mDs.getCurrentOffsetStrMsg()));
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "\nError Message: {}\n\n", e.what()));
}
catch(...)
{
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "--------ERROR REPORT--------"));
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "Unknown exception caught!\n"));
}
}


fs::path Container::extractContainer(const fs::path& aFile, const fs::path& aOutDir) const
{
ContainerExtractor extractor{aFile};
Expand Down
1 change: 0 additions & 1 deletion src/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class Container
}

private:
void exceptionHandling();

size_t mFileCtr; //!< Counts all files that were opened for parsing
size_t mFileErrCtr; //!< Counts all files that failed somewhere
Expand Down
25 changes: 25 additions & 0 deletions src/Stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <optional>
#include <utility>

#include <fmt/color.h>
#include <fmt/core.h>
#include <spdlog/spdlog.h>

#include "ContainerContext.hpp"
#include "Enums/Structure.hpp"
#include "FutureData.hpp"
Expand Down Expand Up @@ -39,6 +43,27 @@ class Stream : public Component
mCtx.mDs.close();
}

void exceptionHandling()
{
try
{
throw;
}
catch(const std::exception& e)
{
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "--------ERROR REPORT--------"));
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "Input Container: {}", mCtx.mInputCfbfFile.string()));
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "Current File: {}", mCtx.mInputStream.string()));
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), mCtx.mDs.getCurrentOffsetStrMsg()));
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "\nError Message: {}\n\n", e.what()));
}
catch(...)
{
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "--------ERROR REPORT--------"));
mCtx.mLogger.error(fmt::format(fg(fmt::color::crimson), "Unknown exception caught!\n"));
}
}

// protected:
StreamContext mCtx;
};
Expand Down

0 comments on commit 1231f86

Please sign in to comment.