diff --git a/src/query/common.hpp b/src/query/common.hpp index 72f020c3f..70e991e90 100644 --- a/src/query/common.hpp +++ b/src/query/common.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "query/db_accessor.hpp" #include "query/exceptions.hpp" @@ -21,6 +22,10 @@ namespace impl { bool TypedValueCompare(const TypedValue &a, const TypedValue &b); } // namespace impl +constexpr inline std::string_view kSerializationErrorMessage{ + "Cannot resolve conflicting transactions. You can retry this transaction when the conflicting transaction is " + "finished."}; + /// Custom Comparator type for comparing vectors of TypedValues. /// /// Does lexicographical ordering of elements based on the above @@ -66,8 +71,7 @@ inline void ExpectType(const Symbol &symbol, const TypedValue &value, TypedValue template concept AccessorWithSetProperty = requires(T accessor, const storage::PropertyId key, const storage::PropertyValue new_value) { - { accessor.SetProperty(key, new_value) } - ->std::same_as>; + { accessor.SetProperty(key, new_value) } -> std::same_as>; }; /// Set a property `value` mapped with given `key` on a `record`. @@ -80,7 +84,7 @@ storage::PropertyValue PropsSetChecked(T *record, const storage::PropertyId &key if (maybe_old_value.HasError()) { switch (maybe_old_value.GetError()) { case storage::Error::SERIALIZATION_ERROR: - throw QueryRuntimeException("Can't serialize due to concurrent operations."); + throw QueryRuntimeException(kSerializationErrorMessage); case storage::Error::DELETED_OBJECT: throw QueryRuntimeException("Trying to set properties on a deleted object."); case storage::Error::PROPERTIES_DISABLED: diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 8dd413c27..8cf25ec77 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -166,7 +166,7 @@ VertexAccessor &CreateLocalVertex(const NodeCreationInfo &node_info, Frame *fram if (maybe_error.HasError()) { switch (maybe_error.GetError()) { case storage::Error::SERIALIZATION_ERROR: - throw QueryRuntimeException("Can't serialize due to concurrent operations."); + throw QueryRuntimeException(kSerializationErrorMessage); case storage::Error::DELETED_OBJECT: throw QueryRuntimeException("Trying to set a label on a deleted node."); case storage::Error::VERTEX_HAS_EDGES: @@ -260,7 +260,7 @@ EdgeAccessor CreateEdge(const EdgeCreationInfo &edge_info, DbAccessor *dba, Vert } else { switch (maybe_edge.GetError()) { case storage::Error::SERIALIZATION_ERROR: - throw QueryRuntimeException("Can't serialize due to concurrent operations."); + throw QueryRuntimeException(kSerializationErrorMessage); case storage::Error::DELETED_OBJECT: throw QueryRuntimeException("Trying to create an edge on a deleted node."); case storage::Error::VERTEX_HAS_EDGES: @@ -1839,7 +1839,7 @@ bool Delete::DeleteCursor::Pull(Frame &frame, ExecutionContext &context) { if (maybe_value.HasError()) { switch (maybe_value.GetError()) { case storage::Error::SERIALIZATION_ERROR: - throw QueryRuntimeException("Can't serialize due to concurrent operations."); + throw QueryRuntimeException(kSerializationErrorMessage); case storage::Error::DELETED_OBJECT: case storage::Error::VERTEX_HAS_EDGES: case storage::Error::PROPERTIES_DISABLED: @@ -1865,7 +1865,7 @@ bool Delete::DeleteCursor::Pull(Frame &frame, ExecutionContext &context) { if (res.HasError()) { switch (res.GetError()) { case storage::Error::SERIALIZATION_ERROR: - throw QueryRuntimeException("Can't serialize due to concurrent operations."); + throw QueryRuntimeException(kSerializationErrorMessage); case storage::Error::DELETED_OBJECT: case storage::Error::VERTEX_HAS_EDGES: case storage::Error::PROPERTIES_DISABLED: @@ -1885,7 +1885,7 @@ bool Delete::DeleteCursor::Pull(Frame &frame, ExecutionContext &context) { if (res.HasError()) { switch (res.GetError()) { case storage::Error::SERIALIZATION_ERROR: - throw QueryRuntimeException("Can't serialize due to concurrent operations."); + throw QueryRuntimeException(kSerializationErrorMessage); case storage::Error::VERTEX_HAS_EDGES: throw RemoveAttachedVertexException(); case storage::Error::DELETED_OBJECT: @@ -2013,9 +2013,8 @@ namespace { template concept AccessorWithProperties = requires(T value, storage::PropertyId property_id, storage::PropertyValue property_value) { - { value.ClearProperties() } - ->std::same_as>>; - {value.SetProperty(property_id, property_value)}; + { value.ClearProperties() } -> std::same_as>>; + { value.SetProperty(property_id, property_value) }; }; /// Helper function that sets the given values on either a Vertex or an Edge. @@ -2036,7 +2035,7 @@ void SetPropertiesOnRecord(TRecordAccessor *record, const TypedValue &rhs, SetPr case storage::Error::DELETED_OBJECT: throw QueryRuntimeException("Trying to set properties on a deleted graph element."); case storage::Error::SERIALIZATION_ERROR: - throw QueryRuntimeException("Can't serialize due to concurrent operations."); + throw QueryRuntimeException(kSerializationErrorMessage); case storage::Error::PROPERTIES_DISABLED: throw QueryRuntimeException("Can't set property because properties on edges are disabled."); case storage::Error::VERTEX_HAS_EDGES: @@ -2092,7 +2091,7 @@ void SetPropertiesOnRecord(TRecordAccessor *record, const TypedValue &rhs, SetPr case storage::Error::DELETED_OBJECT: throw QueryRuntimeException("Trying to set properties on a deleted graph element."); case storage::Error::SERIALIZATION_ERROR: - throw QueryRuntimeException("Can't serialize due to concurrent operations."); + throw QueryRuntimeException(kSerializationErrorMessage); case storage::Error::PROPERTIES_DISABLED: throw QueryRuntimeException("Can't set property because properties on edges are disabled."); case storage::Error::VERTEX_HAS_EDGES: @@ -2207,7 +2206,7 @@ bool SetLabels::SetLabelsCursor::Pull(Frame &frame, ExecutionContext &context) { if (maybe_value.HasError()) { switch (maybe_value.GetError()) { case storage::Error::SERIALIZATION_ERROR: - throw QueryRuntimeException("Can't serialize due to concurrent operations."); + throw QueryRuntimeException(kSerializationErrorMessage); case storage::Error::DELETED_OBJECT: throw QueryRuntimeException("Trying to set a label on a deleted node."); case storage::Error::VERTEX_HAS_EDGES: @@ -2265,7 +2264,7 @@ bool RemoveProperty::RemovePropertyCursor::Pull(Frame &frame, ExecutionContext & case storage::Error::DELETED_OBJECT: throw QueryRuntimeException("Trying to remove a property on a deleted graph element."); case storage::Error::SERIALIZATION_ERROR: - throw QueryRuntimeException("Can't serialize due to concurrent operations."); + throw QueryRuntimeException(kSerializationErrorMessage); case storage::Error::PROPERTIES_DISABLED: throw QueryRuntimeException( "Can't remove property because properties on edges are " @@ -2336,7 +2335,7 @@ bool RemoveLabels::RemoveLabelsCursor::Pull(Frame &frame, ExecutionContext &cont if (maybe_value.HasError()) { switch (maybe_value.GetError()) { case storage::Error::SERIALIZATION_ERROR: - throw QueryRuntimeException("Can't serialize due to concurrent operations."); + throw QueryRuntimeException(kSerializationErrorMessage); case storage::Error::DELETED_OBJECT: throw QueryRuntimeException("Trying to remove labels from a deleted node."); case storage::Error::VERTEX_HAS_EDGES: diff --git a/src/utils/exceptions.hpp b/src/utils/exceptions.hpp index 908b86018..df5e7d9c3 100644 --- a/src/utils/exceptions.hpp +++ b/src/utils/exceptions.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include @@ -43,6 +44,13 @@ class BasicException : public std::exception { */ explicit BasicException(const std::string &message) noexcept : msg_(message) {} + /** + * @brief Constructor (C++ STL string_view). + * + * @param message The error message. + */ + explicit BasicException(const std::string_view message) noexcept : msg_(message) {} + /** * @brief Constructor with format string (C++ STL strings). *