Expand SHARD_ERROR with fmt format
This commit is contained in:
parent
5717dfb165
commit
f1e360469a
@ -48,10 +48,6 @@ class NameIdMapper final {
|
||||
return kUnmappedId;
|
||||
}
|
||||
|
||||
const std::string &IdToName(const LabelId label_id) const { return IdToName(label_id.AsInt()); }
|
||||
|
||||
const std::string &IdToName(const PropertyId property_id) const { return IdToName(property_id.AsInt()); }
|
||||
|
||||
const std::string &IdToName(const uint64_t id) const {
|
||||
auto it = id_to_name_.find(id);
|
||||
MG_ASSERT(it != id_to_name_.end(), "Id not know in mapper!");
|
||||
|
@ -42,10 +42,10 @@ struct ShardError {
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||
#define SHARD_ERROR(...) \
|
||||
({ \
|
||||
using ErrorCode = memgraph::common::ErrorCode; \
|
||||
memgraph::storage::v3::ShardError(__VA_ARGS__, std::experimental::source_location::current()); \
|
||||
#define SHARD_ERROR(error, ...) \
|
||||
({ \
|
||||
using ErrorCode = memgraph::common::ErrorCode; \
|
||||
memgraph::storage::v3::ShardError(error, GET_MESSAGE(__VA_ARGS__), std::experimental::source_location::current()); \
|
||||
})
|
||||
|
||||
template <class TValue>
|
||||
|
@ -31,35 +31,34 @@ std::optional<ShardError> SchemaValidator::ValidateVertexCreate(
|
||||
// Schema on primary label
|
||||
const auto *schema = schemas_->GetSchema(primary_label);
|
||||
if (schema == nullptr) {
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL,
|
||||
fmt::format("Schema not defined for label :{}", name_id_mapper_->IdToName(primary_label)));
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL, "Schema not defined for label :{}",
|
||||
name_id_mapper_->IdToName(primary_label.AsInt()));
|
||||
}
|
||||
|
||||
// Is there another primary label among secondary labels
|
||||
for (const auto &secondary_label : labels) {
|
||||
if (schemas_->GetSchema(secondary_label)) {
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY,
|
||||
fmt::format("Cannot add label :{}, since it is defined as a primary label",
|
||||
name_id_mapper_->IdToName(secondary_label)));
|
||||
"Cannot add label :{}, since it is defined as a primary label",
|
||||
name_id_mapper_->IdToName(secondary_label.AsInt()));
|
||||
}
|
||||
}
|
||||
|
||||
// Quick size check
|
||||
if (schema->second.size() != primary_properties.size()) {
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED,
|
||||
fmt::format("Not all primary properties have been specified for :{} vertex",
|
||||
name_id_mapper_->IdToName(primary_label)));
|
||||
"Not all primary properties have been specified for :{} vertex",
|
||||
name_id_mapper_->IdToName(primary_label.AsInt()));
|
||||
}
|
||||
// Check only properties defined by schema
|
||||
for (size_t i{0}; i < schema->second.size(); ++i) {
|
||||
// Check schema property type
|
||||
if (auto property_schema_type = PropertyTypeToSchemaType(primary_properties[i]);
|
||||
property_schema_type && *property_schema_type != schema->second[i].type) {
|
||||
return SHARD_ERROR(
|
||||
common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE,
|
||||
fmt::format("Property {} is of wrong type, expected {}, actual {}",
|
||||
name_id_mapper_->IdToName(schema->second[i].property_id),
|
||||
SchemaTypeToString(schema->second[i].type), SchemaTypeToString(*property_schema_type)));
|
||||
return SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE,
|
||||
"Property {} is of wrong type, expected {}, actual {}",
|
||||
name_id_mapper_->IdToName(schema->second[i].property_id.AsInt()),
|
||||
SchemaTypeToString(schema->second[i].type), SchemaTypeToString(*property_schema_type));
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,10 +76,10 @@ std::optional<ShardError> SchemaValidator::ValidatePropertyUpdate(const LabelId
|
||||
schema->second,
|
||||
[property_id](const auto &schema_property) { return property_id == schema_property.property_id; });
|
||||
schema_property != schema->second.end()) {
|
||||
return SHARD_ERROR(
|
||||
common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY,
|
||||
fmt::format("Cannot update primary property {} of schema on label :{}",
|
||||
name_id_mapper_->IdToName(schema_property->property_id), name_id_mapper_->IdToName(primary_label)));
|
||||
return SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY,
|
||||
"Cannot update primary property {} of schema on label :{}",
|
||||
name_id_mapper_->IdToName(schema_property->property_id.AsInt()),
|
||||
name_id_mapper_->IdToName(primary_label.AsInt()));
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
@ -88,8 +87,8 @@ std::optional<ShardError> SchemaValidator::ValidatePropertyUpdate(const LabelId
|
||||
std::optional<ShardError> SchemaValidator::ValidateLabelUpdate(const LabelId label) const {
|
||||
const auto *schema = schemas_->GetSchema(label);
|
||||
if (schema) {
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL,
|
||||
fmt::format("Cannot add/remove primary label :{}", name_id_mapper_->IdToName(label)));
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL, "Cannot add/remove primary label :{}",
|
||||
name_id_mapper_->IdToName(label.AsInt()));
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user