Skip to content

Commit 1ed84e6

Browse files
compwronclaude
andcommitted
fix: add template validation for sablon 0.4.3 compatibility
Sablon 0.4.3 no longer raises Zip::Error for nonexistent template files, instead returning an empty ZIP. This breaks the error handling in CaseCourtReportsController that relies on catching Zip::Error to show users a friendly "Template is not found" message. Changes: - Add file existence validation in CaseCourtReport#initialize - Raise Zip::Error with descriptive message if template doesn't exist - Update test to expect error during initialization (fail-fast approach) - Maintain backward compatibility with existing error handling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent cd9a51b commit 1ed84e6

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

app/models/case_court_report.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class CaseCourtReport
77

88
def initialize(path_to_template:, context:)
99
@context = context
10+
# Validate template exists before processing (sablon 0.4+ no longer raises Zip::Error)
11+
raise Zip::Error, "Template file not found: #{path_to_template}" unless File.exist?(path_to_template)
1012
# NOTE: this is what is used for docx templates
1113
@template = Sablon.template(path_to_template)
1214
end

spec/models/case_court_report_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,9 @@
393393
path_to_template: nonexistent_path
394394
}
395395
context = CaseCourtReportContext.new(args).context
396-
bad_report = CaseCourtReport.new(path_to_template: nonexistent_path, context: context)
397-
expect { bad_report.generate_to_string }.to raise_error(Zip::Error)
396+
expect {
397+
CaseCourtReport.new(path_to_template: nonexistent_path, context: context)
398+
}.to raise_error(Zip::Error, /Template file not found/)
398399
end
399400
end
400401

0 commit comments

Comments
 (0)