From 97a22003128444aa055cdeb6d601d163cb0fc5dd Mon Sep 17 00:00:00 2001 From: Dimitris Christodoulou Date: Tue, 14 Mar 2023 10:31:26 +0000 Subject: [PATCH] Add optional context parameter to error constructors --- lib/couchbase/errors.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/couchbase/errors.rb b/lib/couchbase/errors.rb index 7e9c372b..644ea8d1 100644 --- a/lib/couchbase/errors.rb +++ b/lib/couchbase/errors.rb @@ -21,6 +21,11 @@ class CouchbaseError < StandardError # @return [Hash] attributes associated with the error attr_reader :context + def initialize(msg = nil, context = nil) + @context = context unless context.nil? + super(msg) + end + def to_s defined?(@context) ? "#{super}, context=#{JSON.generate(@context)}" : super end @@ -30,6 +35,11 @@ class InvalidArgument < ArgumentError # @return [Hash] attributes associated with the error attr_reader :context + def initialize(msg = nil, context = nil) + @context = context unless context.nil? + super(msg) + end + def to_s defined?(@context) ? "#{super}, context=#{JSON.generate(@context)}" : super end