From 132bcf2bdbe2bfe3e61a420bd147bc595215e17b Mon Sep 17 00:00:00 2001 From: Giallombardo Nathan Date: Mon, 21 Aug 2023 07:24:45 +0000 Subject: [PATCH] raise CouchbaseOrm::Error::RecordInvalid (cherry picked from commit 13d3bee12659eb5f858dd1b47525fb0a66139de4) --- lib/couchbase-orm/base.rb | 6 ++++++ lib/couchbase-orm/error.rb | 16 ++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/couchbase-orm/base.rb b/lib/couchbase-orm/base.rb index a9996766..8dece9b7 100644 --- a/lib/couchbase-orm/base.rb +++ b/lib/couchbase-orm/base.rb @@ -339,5 +339,11 @@ def eql?(other) def ==(other) super || other.instance_of?(self.class) && !id.nil? && other.id == id end + + private + + def raise_validation_error + raise CouchbaseOrm::Error::RecordInvalid.new(self) + end end end diff --git a/lib/couchbase-orm/error.rb b/lib/couchbase-orm/error.rb index 6aa7ebcc..aaab0e3e 100644 --- a/lib/couchbase-orm/error.rb +++ b/lib/couchbase-orm/error.rb @@ -10,20 +10,20 @@ def initialize(message = nil, record = nil) end class RecordInvalid < Error - def initialize(message = nil, record = nil) + def initialize(record = nil) if record - errors = record.errors.full_messages.join(", ") - message = I18n.t( - :"couchbase.#{record.class.design_document}.errors.messages.record_invalid", - errors: errors, - default: :"couchbase.errors.messages.record_invalid" - ) + @record = record + errors = @record.errors.full_messages.join(", ") + message = I18n.t(:"#{@record.class.i18n_scope}.errors.messages.record_invalid", errors: errors, default: :"errors.messages.record_invalid") + else + message = "Record invalid" end super(message, record) end end class TypeMismatchError < Error; end class RecordExists < Error; end - class CouchbaseOrm::Error::EmptyNotAllowed < Error; end + class EmptyNotAllowed < Error; end + class DocumentNotFound < Error; end end end