Skip to content

Commit 8bdd11e

Browse files
committed
Raise Pluto::Exception instead of the generic Exception
1 parent 2e4d553 commit 8bdd11e

File tree

9 files changed

+17
-17
lines changed

9 files changed

+17
-17
lines changed

spec/pluto/operation/crop_spec.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ describe Pluto::Operation::Crop do
55
it "checks image width boundaries" do
66
image = ga_sample
77

8-
expect_raises(Exception, "Crop dimensions extend 1 pixels beyond width of the image (640)") do
8+
expect_raises(Pluto::Exception, "Crop dimensions extend 1 pixels beyond width of the image (640)") do
99
image.crop(0, 0, image.width + 1, image.height)
1010
end
1111
end
1212

1313
it "checks image height boundaries" do
1414
image = ga_sample
1515

16-
expect_raises(Exception, "Crop dimensions extend 1 pixels beyond height of the image (480)") do
16+
expect_raises(Pluto::Exception, "Crop dimensions extend 1 pixels beyond height of the image (480)") do
1717
image.crop(0, 0, image.width, image.height + 1)
1818
end
1919
end

spec/pluto/operation/rotation_spec.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe Pluto::Operation::Rotation do
55
it "checks padding and radius" do
66
image = ga_sample
77

8-
expect_raises(Exception, "Can't pad image and limit rotation by radius") do
8+
expect_raises(Pluto::Exception, "Can't pad image and limit rotation by radius") do
99
image.rotation(0, padding: true, radius: 1)
1010
end
1111
end

src/pluto/format/jpeg.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module Pluto::Format::JPEG
5050
message = String.new(Format::Binding::LibJPEGTurbo.get_error_str(handle))
5151
error_code = Format::Binding::LibJPEGTurbo.get_error_code(handle).to_i
5252

53-
raise ::Pluto::Exception.new(message, error_code) unless code == 0
53+
raise Exception.new(message, error_code) unless code == 0
5454
end
5555
end
5656

src/pluto/format/png.cr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Pluto::Format::PNG
44
macro included
55
def self.from_png(image_data : Bytes) : self
66
ctx = Format::Binding::LibSPNG.ctx_new(Format::Binding::LibSPNG::CtxFlags::None)
7-
raise ::Pluto::Exception.new("Failed to create a context") unless ctx
7+
raise Exception.new("Failed to create a context") unless ctx
88

99
Format::Binding::LibSPNG.set_png_buffer(ctx, image_data, image_data.size)
1010

@@ -47,7 +47,7 @@ module Pluto::Format::PNG
4747
end
4848

4949
protected def self.check_png(code)
50-
raise ::Pluto::Exception.new(code) if code != 0
50+
raise Exception.new(code) if code != 0
5151
end
5252
end
5353

@@ -61,7 +61,7 @@ module Pluto::Format::PNG
6161
end
6262

6363
ctx = Format::Binding::LibSPNG.ctx_new(Format::Binding::LibSPNG::CtxFlags::Encoder)
64-
raise ::Pluto::Exception.new("Failed to create a context") unless ctx
64+
raise Exception.new("Failed to create a context") unless ctx
6565

6666
Format::Binding::LibSPNG.set_option(ctx, Format::Binding::LibSPNG::Option::EncodeToBuffer, true)
6767
Format::Binding::LibSPNG.set_png_buffer(ctx, image_data.buffer, image_data.size)
@@ -83,7 +83,7 @@ module Pluto::Format::PNG
8383
check_png error
8484

8585
buffer = Format::Binding::LibSPNG.get_png_buffer(ctx, out size, pointerof(error))
86-
raise ::Pluto::Exception.new("Failed to get a buffer") unless ctx
86+
raise Exception.new("Failed to get a buffer") unless ctx
8787

8888
bytes = Bytes.new(buffer, size)
8989
io.write(bytes)

src/pluto/format/ppm.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ module Pluto::Format::PPM
2525
green.unsafe_put(index, green_byte)
2626
blue.unsafe_put(index, blue_byte)
2727
else
28-
raise "The image ends prematurely"
28+
raise Exception.new("The image ends prematurely")
2929
end
3030
end
3131

3232
new(red, green, blue, alpha, width, height)
3333
else
34-
raise "The image doesn't have width or height"
34+
raise Exception.new("The image doesn't have width or height")
3535
end
3636
end
3737
end

src/pluto/format/webp.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module Pluto::Format::WebP
3434
end
3535

3636
protected def self.check_webp(code)
37-
raise ::Pluto::Exception.new(code.to_i) if code == 0
37+
raise Exception.new(code.to_i) if code == 0
3838
end
3939
end
4040

src/pluto/image_ga.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ class Pluto::ImageGA < Pluto::Image
5151
case channel_type
5252
when ChannelType::Gray then @gray
5353
when ChannelType::Alpha then @alpha
54-
else raise "Unknown channel type #{channel_type} for ImageRGBA"
54+
else raise Exception.new("Unknown channel type #{channel_type} for ImageRGBA")
5555
end
5656
end
5757

5858
def []=(channel_type : ChannelType, channel : Array(UInt8)) : Array(UInt8)
5959
case channel_type
6060
when ChannelType::Gray then self.gray = channel
6161
when ChannelType::Alpha then self.alpha = channel
62-
else raise "Unknown channel type #{channel_type} for ImageGA"
62+
else raise Exception.new("Unknown channel type #{channel_type} for ImageGA")
6363
end
6464
end
6565

src/pluto/image_rgba.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Pluto::ImageRGBA < Pluto::Image
3636
when ChannelType::Green then @green
3737
when ChannelType::Blue then @blue
3838
when ChannelType::Alpha then @alpha
39-
else raise "Unknown channel type #{channel_type} for ImageRGBA"
39+
else raise Exception.new("Unknown channel type #{channel_type} for ImageRGBA")
4040
end
4141
end
4242

@@ -46,7 +46,7 @@ class Pluto::ImageRGBA < Pluto::Image
4646
when ChannelType::Green then @green = channel
4747
when ChannelType::Blue then @blue = channel
4848
when ChannelType::Alpha then @alpha = channel
49-
else raise "Unknown channel type #{channel_type} for ImageRGBA"
49+
else raise Exception.new("Unknown channel type #{channel_type} for ImageRGBA")
5050
end
5151
end
5252

src/pluto/operation/crop.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module Pluto::Operation::Crop
44
end
55

66
def crop!(x : Int32, y : Int32, new_width : Int32, new_height : Int32) : self
7-
raise "Crop dimensions extend #{x + new_width - width} pixels beyond width of the image (#{width})" if (x + new_width) > width
8-
raise "Crop dimensions extend #{y + new_height - height} pixels beyond height of the image (#{height})" if (y + new_height) > height
7+
raise Exception.new("Crop dimensions extend #{x + new_width - width} pixels beyond width of the image (#{width})") if (x + new_width) > width
8+
raise Exception.new("Crop dimensions extend #{y + new_height - height} pixels beyond height of the image (#{height})") if (y + new_height) > height
99

1010
new_size = new_width * new_height
1111
height_offset = y * width

0 commit comments

Comments
 (0)