Better logging when local state can't be loaded

This commit is contained in:
Sebastian Messmer 2019-05-25 12:27:31 -07:00
parent 0ee707397d
commit 7d40937b9a
4 changed files with 33 additions and 15 deletions

View File

@ -1,5 +1,7 @@
Version 0.10.2 (unreleased) Version 0.10.2 (unreleased)
--------------- ---------------
Improvements:
* Better logging when local state can't be loaded
Version 0.10.1 Version 0.10.1

View File

@ -40,6 +40,7 @@ CryConfig::CryConfig()
CryConfig CryConfig::load(const Data &data) { CryConfig CryConfig::load(const Data &data) {
stringstream stream; stringstream stream;
data.StoreToStream(stream); data.StoreToStream(stream);
ptree pt; ptree pt;
read_json(stream, pt); read_json(stream, pt);

View File

@ -4,6 +4,7 @@
#include <vendor_cryptopp/sha.h> #include <vendor_cryptopp/sha.h>
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include "LocalStateDir.h" #include "LocalStateDir.h"
#include <cpp-utils/logging/logging.h>
namespace bf = boost::filesystem; namespace bf = boost::filesystem;
using boost::property_tree::ptree; using boost::property_tree::ptree;
@ -15,12 +16,14 @@ using std::istream;
using std::ifstream; using std::ifstream;
using std::ofstream; using std::ofstream;
using std::string; using std::string;
using namespace cpputils::logging;
namespace cryfs { namespace cryfs {
namespace { namespace {
ptree _load(const bf::path &metadataFilePath) { ptree _load(const bf::path &metadataFilePath) {
try {
ptree result; ptree result;
ifstream file(metadataFilePath.string()); ifstream file(metadataFilePath.string());
@ -30,6 +33,11 @@ ptree _load(const bf::path &metadataFilePath) {
return result; return result;
} }
catch (...) {
LOG(ERR, "Error loading BasedirMetadata");
throw;
}
}
void _save(const bf::path &metadataFilePath, const ptree& data) { void _save(const bf::path &metadataFilePath, const ptree& data) {
ofstream file(metadataFilePath.string(), std::ios::trunc); ofstream file(metadataFilePath.string(), std::ios::trunc);

View File

@ -21,6 +21,7 @@ using cpputils::hash::Hash;
using cpputils::Data; using cpputils::Data;
using cpputils::Random; using cpputils::Random;
namespace bf = boost::filesystem; namespace bf = boost::filesystem;
using namespace cpputils::logging;
namespace cryfs { namespace cryfs {
@ -106,6 +107,7 @@ void LocalStateMetadata::_serialize(ostream& stream) const {
} }
LocalStateMetadata LocalStateMetadata::_deserialize(istream& stream) { LocalStateMetadata LocalStateMetadata::_deserialize(istream& stream) {
try {
ptree pt; ptree pt;
read_json(stream, pt); read_json(stream, pt);
@ -118,5 +120,10 @@ LocalStateMetadata LocalStateMetadata::_deserialize(istream& stream) {
/*.salt = */ cpputils::hash::Salt::FromString(encryptionKeySalt) /*.salt = */ cpputils::hash::Salt::FromString(encryptionKeySalt)
}); });
} }
catch (...) {
LOG(ERR, "Error loading LocalStateMetadata");
throw;
}
}
} }