Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
(#18) Better error messages
Browse files Browse the repository at this point in the history
Included boost::format for generating formatted strings in the
exception messages.
  • Loading branch information
leandor committed Jul 1, 2017
1 parent d68e263 commit 3078f51
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/papi/lz4/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

#include "module.h"

#include <boost/format.hpp>

#include <gsl/gsl>
#include <string>
#include <vector>
#include <tuple>

using boost::format;

py::bytes lz4::compress(const py::bytes& buffer)
{
Expand All @@ -18,8 +21,9 @@ py::bytes lz4::compress(const py::bytes& buffer)

auto res = api::compress_default(source, dest);

if (res == 0) {
throw std::exception("compression failed");
if (res <= 0) {
const auto errorMsg = (format("LZ4: compression failed with result code: %1%") % res).str();
throw std::exception(errorMsg.c_str());
}

return py::bytes(dest.data(), res);
Expand Down

0 comments on commit 3078f51

Please sign in to comment.