2015-06-10 22:45:29 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2015-06-11 17:33:46 +00:00
|
|
|
// Copyright 2015 Realm Inc.
|
2015-06-10 22:45:29 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef REALM_OBJECT_STORE_EXCEPTIONS_HPP
|
|
|
|
#define REALM_OBJECT_STORE_EXCEPTIONS_HPP
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2015-06-16 23:19:34 +00:00
|
|
|
#define INFO_KEY(key) InfoKey InfoKey##key = "InfoKey" #key;
|
|
|
|
|
2015-06-10 22:45:29 +00:00
|
|
|
namespace realm {
|
2015-06-16 17:07:40 +00:00
|
|
|
class Property;
|
2015-06-10 22:45:29 +00:00
|
|
|
|
|
|
|
class ObjectStoreException : public std::exception {
|
|
|
|
public:
|
|
|
|
enum class Kind {
|
2015-06-16 17:07:40 +00:00
|
|
|
RealmVersionGreaterThanSchemaVersion, // OldVersion, NewVersion
|
|
|
|
RealmPropertyTypeNotIndexable, // ObjectType, PropertyName, PropertyType
|
|
|
|
RealmDuplicatePrimaryKeyValue, // ObjectType, PropertyName, PropertyType
|
|
|
|
ObjectSchemaMissingProperty, // ObjectType, PropertyName, PropertyType
|
|
|
|
ObjectSchemaNewProperty, // ObjectType, PropertyName, PropertyType
|
|
|
|
ObjectSchemaMismatchedTypes, // ObjectType, PropertyName, PropertyType, OldPropertyType
|
|
|
|
ObjectSchemaMismatchedObjectTypes, // ObjectType, PropertyName, PropertyType, ObjectType, OldObjectType
|
2015-06-16 23:19:34 +00:00
|
|
|
ObjectSchemaChangedPrimaryKey, // ObjectType, PrimaryKey
|
|
|
|
ObjectSchemaNewPrimaryKey, // ObjectType, PrimaryKey
|
2015-06-16 17:07:40 +00:00
|
|
|
ObjectStoreValidationFailure, // ObjectType, vector<ObjectStoreException>
|
2015-06-10 22:45:29 +00:00
|
|
|
};
|
|
|
|
|
2015-06-16 23:19:34 +00:00
|
|
|
typedef const std::string InfoKey;
|
2015-06-16 17:07:40 +00:00
|
|
|
typedef std::map<InfoKey, std::string> Info;
|
|
|
|
|
|
|
|
ObjectStoreException(Kind kind, const std::string &object_type, const Property &prop);
|
2015-06-16 23:19:34 +00:00
|
|
|
|
|
|
|
// ObjectSchemaMismatchedTypes, ObjectSchemaMismatchedObjectTypes
|
2015-06-16 17:07:40 +00:00
|
|
|
ObjectStoreException(Kind kind, const std::string &object_type, const Property &prop, const Property &oldProp);
|
|
|
|
|
2015-06-16 23:19:34 +00:00
|
|
|
// ObjectSchemaChangedPrimaryKey, ObjectSchemaNewPrimaryKey
|
|
|
|
ObjectStoreException(Kind kind, const std::string &object_type, const std::string primary_key);
|
|
|
|
|
|
|
|
// RealmVersionGreaterThanSchemaVersion
|
|
|
|
ObjectStoreException(uint64_t old_version, uint64_t new_version);
|
|
|
|
|
2015-06-16 17:07:40 +00:00
|
|
|
// ObjectStoreValidationFailure
|
|
|
|
ObjectStoreException(std::vector<ObjectStoreException> validation_errors, const std::string &object_type);
|
2015-06-10 22:45:29 +00:00
|
|
|
|
|
|
|
ObjectStoreException::Kind kind() const { return m_kind; }
|
2015-06-16 17:07:40 +00:00
|
|
|
const ObjectStoreException::Info &info() const { return m_info; }
|
2015-06-10 22:45:29 +00:00
|
|
|
|
|
|
|
const char *what() const noexcept override { return m_what.c_str(); }
|
|
|
|
|
2015-06-16 17:07:40 +00:00
|
|
|
// implement CustomWhat to customize exception messages per platform/language
|
2015-06-16 23:19:34 +00:00
|
|
|
typedef std::map<Kind, std::string> FormatStrings;
|
|
|
|
static void set_custom_format_strings(FormatStrings custom_format_strings) { s_custom_format_strings = custom_format_strings; }
|
2015-06-16 17:36:40 +00:00
|
|
|
|
2015-06-10 22:45:29 +00:00
|
|
|
private:
|
2015-06-16 23:19:34 +00:00
|
|
|
ObjectStoreException(Kind kind, Info info = Info());
|
|
|
|
|
2015-06-10 22:45:29 +00:00
|
|
|
Kind m_kind;
|
2015-06-16 17:07:40 +00:00
|
|
|
Info m_info;
|
|
|
|
std::vector<ObjectStoreException> m_validation_errors;
|
2015-06-10 22:45:29 +00:00
|
|
|
|
|
|
|
std::string m_what;
|
2015-06-16 23:19:34 +00:00
|
|
|
std::string generate_what() const;
|
|
|
|
std::string validation_errors_string() const;
|
|
|
|
std::string populate_format_string(const std::string &format_string) const;
|
2015-06-16 17:07:40 +00:00
|
|
|
|
2015-06-16 23:19:34 +00:00
|
|
|
static const FormatStrings s_default_format_strings;
|
|
|
|
static FormatStrings s_custom_format_strings;
|
|
|
|
|
|
|
|
public:
|
|
|
|
INFO_KEY(OldVersion);
|
|
|
|
INFO_KEY(NewVersion);
|
|
|
|
INFO_KEY(ObjectType);
|
|
|
|
INFO_KEY(PropertyName);
|
|
|
|
INFO_KEY(PropertyType);
|
|
|
|
INFO_KEY(OldPropertyType);
|
|
|
|
INFO_KEY(PropertyObjectType);
|
|
|
|
INFO_KEY(OldPropertyObjectType);
|
|
|
|
INFO_KEY(PrimaryKey);
|
2015-06-10 22:45:29 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* defined(REALM_OBJECT_STORE_EXCEPTIONS_HPP) */
|