From 23d9c1c6e84f8f31cb3f0458e13579b3be4762e8 Mon Sep 17 00:00:00 2001 From: kishikawa katsumi Date: Tue, 16 Feb 2016 22:01:19 +0900 Subject: [PATCH] Split SchemaValidationException into SchemaValidationException and SchemaMismatchException Because SchemaValidationException is thrown both case that a schema definition is incorrect and case that two schema definitions are mismatched. In the former case, the migration does not solve the problem. But the exception message shows "Migration is required..." Therefore the latter as MismatchException, to distinguish between the two cases. --- src/object_store.cpp | 13 +++++++++++-- src/object_store.hpp | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/object_store.cpp b/src/object_store.cpp index 94c309e8..565d5ac0 100644 --- a/src/object_store.cpp +++ b/src/object_store.cpp @@ -171,7 +171,7 @@ void ObjectStore::verify_schema(Schema const& actual_schema, Schema& target_sche errors.insert(errors.end(), more_errors.begin(), more_errors.end()); } if (errors.size()) { - throw SchemaValidationException(errors); + throw SchemaMismatchException(errors); } } @@ -524,7 +524,16 @@ DuplicatePrimaryKeyValueException::DuplicatePrimaryKeyValueException(std::string SchemaValidationException::SchemaValidationException(std::vector const& errors) : m_validation_errors(errors) { - m_what ="Migration is required due to the following errors: "; + m_what = "Schema validation failed due to the following errors: "; + for (auto const& error : errors) { + m_what += std::string("\n- ") + error.what(); + } +} + +SchemaMismatchException::SchemaMismatchException(std::vector const& errors) : +m_validation_errors(errors) +{ + m_what = "Migration is required due to the following errors: "; for (auto const& error : errors) { m_what += std::string("\n- ") + error.what(); } diff --git a/src/object_store.hpp b/src/object_store.hpp index bfbc6acc..28b75c89 100644 --- a/src/object_store.hpp +++ b/src/object_store.hpp @@ -160,6 +160,14 @@ namespace realm { std::vector m_validation_errors; }; + class SchemaMismatchException : public ObjectStoreException { + public: + SchemaMismatchException(std::vector const& errors); + std::vector const& validation_errors() const { return m_validation_errors; } + private: + std::vector m_validation_errors; + }; + class ObjectSchemaValidationException : public ObjectStoreException { public: ObjectSchemaValidationException(std::string const& object_type) : m_object_type(object_type) {}