Skip to content

Commit 240cbd9

Browse files
p8zzak
authored andcommitted
Improve InvariableError, UnpreviewableError and UnrepresentableError message
Mention which blob can't be transformed/previewed and what content_type it has. Co-authored-by: zzak <[email protected]>
1 parent f376782 commit 240cbd9

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

activestorage/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Improve InvariableError, UnpreviewableError and UnrepresentableError message.
2+
3+
Include Blob ID and content_type in the messages.
4+
5+
*Petrik de Heus*
6+
17
* Mark proxied files as `immutable` in their Cache-Control header
28

39
*Nate Matykiewicz*

activestorage/app/models/active_storage/blob/representable.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def variant(transformations)
3535
if variable?
3636
variant_class.new(self, ActiveStorage::Variation.wrap(transformations).default_to(default_variant_transformations))
3737
else
38-
raise ActiveStorage::InvariableError
38+
raise ActiveStorage::InvariableError, "Can't transform blob with ID=#{id} and content_type=#{content_type}"
3939
end
4040
end
4141

@@ -64,7 +64,7 @@ def preview(transformations)
6464
if previewable?
6565
ActiveStorage::Preview.new(self, transformations)
6666
else
67-
raise ActiveStorage::UnpreviewableError
67+
raise ActiveStorage::UnpreviewableError, "No previewer found for blob with ID=#{id} and content_type=#{content_type}"
6868
end
6969
end
7070

@@ -89,7 +89,7 @@ def representation(transformations)
8989
when variable?
9090
variant transformations
9191
else
92-
raise ActiveStorage::UnrepresentableError
92+
raise ActiveStorage::UnrepresentableError, "No previewer found and can't transform blob with ID=#{id} and content_type=#{content_type}"
9393
end
9494
end
9595

activestorage/test/models/preview_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ class ActiveStorage::PreviewTest < ActiveSupport::TestCase
5858

5959
test "previewing an unpreviewable blob" do
6060
blob = create_file_blob
61-
62-
assert_raises ActiveStorage::UnpreviewableError do
61+
assert_raises ActiveStorage::UnpreviewableError, match: /blob with ID=\d+ and content_type=image\/jpeg/ do
6362
blob.preview resize_to_limit: [640, 280]
6463
end
6564
end

activestorage/test/models/representation_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class ActiveStorage::RepresentationTest < ActiveSupport::TestCase
4242

4343
test "representing an unrepresentable blob" do
4444
blob = create_blob
45-
46-
assert_raises ActiveStorage::UnrepresentableError do
45+
assert_raises ActiveStorage::UnrepresentableError, match: /blob with ID=\d+ and content_type=text\/plain/ do
4746
blob.representation resize_to_limit: [100, 100]
4847
end
4948
end

activestorage/test/models/variant_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
158158
end
159159

160160
test "variation of invariable blob" do
161-
assert_raises ActiveStorage::InvariableError do
161+
assert_raises ActiveStorage::InvariableError, match: /blob with ID=\d+ and content_type=application\/pdf/ do
162162
create_file_blob(filename: "report.pdf", content_type: "application/pdf").variant(resize_to_limit: [100, 100])
163163
end
164164
end

0 commit comments

Comments
 (0)