From 4e0d3c2df1952236e2dc1d25330b3d6b905aa78d Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 11 Oct 2024 11:23:36 +0200 Subject: [PATCH] improve Column not found error message --- app/models/column.rb | 8 +++++++- app/models/concerns/columns_concern.rb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/column.rb b/app/models/column.rb index 662bfda76..b6c6a43d6 100644 --- a/app/models/column.rb +++ b/app/models/column.rb @@ -38,6 +38,12 @@ class Column end def self.find(h_id) - Procedure.with_discarded.find(h_id[:procedure_id]).find_column(h_id:) + begin + procedure = Procedure.with_discarded.find(h_id[:procedure_id]) + rescue ActiveRecord::RecordNotFound + raise ActiveRecord::RecordNotFound.new("Column: unable to find procedure #{h_id[:procedure_id]} from h_id #{h_id}") + end + + procedure.find_column(h_id: h_id) end end diff --git a/app/models/concerns/columns_concern.rb b/app/models/concerns/columns_concern.rb index d21cb1cba..c98a621df 100644 --- a/app/models/concerns/columns_concern.rb +++ b/app/models/concerns/columns_concern.rb @@ -12,7 +12,7 @@ module ColumnsConcern column = columns.find { _1.h_id == h_id } if h_id.present? column = columns.find { _1.label == label } if label.present? - raise ActiveRecord::RecordNotFound if column.nil? + raise ActiveRecord::RecordNotFound.new("Column: unable to find h_id: #{h_id} or label: #{label} for procedure_id #{id}") if column.nil? column end