Skip to content

Commit

Permalink
Propagate original callstack, save a fiber allocation if unnecessary (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Vici37 authored Dec 13, 2024
1 parent ecae4d7 commit f4711b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/granite/connection_management.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ module Granite::ConnectionManagement
end

def self.schedule_adapter_switch
return if @@writer_adapter == @@reader_adapter

spawn do
sleep @@connection_switch_wait_period.milliseconds
switch_to_reader_adapter
Expand Down
10 changes: 5 additions & 5 deletions src/granite/transactions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module Granite::Transactions
end
{% end %}
rescue err
raise DB::Error.new(err.message)
raise DB::Error.new(err.message, cause: err)
end

# Runs an INSERT statement for all records in *model_array*, with options to
Expand All @@ -92,7 +92,7 @@ module Granite::Transactions
end
{% end %}
rescue err
raise DB::Error.new(err.message)
raise DB::Error.new(err.message, cause: err)
end

def import(model_array : Array(self) | Granite::Collection(self), ignore_on_duplicate : Bool, batch_size : Int32 = model_array.size)
Expand All @@ -114,7 +114,7 @@ module Granite::Transactions
end
{% end %}
rescue err
raise DB::Error.new(err.message)
raise DB::Error.new(err.message, cause: err)
end
end

Expand Down Expand Up @@ -176,7 +176,7 @@ module Granite::Transactions
rescue err : DB::Error
raise err
rescue err
raise DB::Error.new(err.message)
raise DB::Error.new(err.message, cause: err)
else
self.new_record = false
end
Expand All @@ -199,7 +199,7 @@ module Granite::Transactions
begin
self.class.adapter.update(self.class.table_name, self.class.primary_name, fields, params)
rescue err
raise DB::Error.new(err.message)
raise DB::Error.new(err.message, cause: err)
end
{% end %}
end
Expand Down

0 comments on commit f4711b6

Please sign in to comment.