Skip to content

Commit

Permalink
feat: bump version
Browse files Browse the repository at this point in the history
and move exceptions to their own file
  • Loading branch information
stakach committed Sep 21, 2022
1 parent d145a79 commit f5b97a6
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ lib
app
*.dwarf
*.DS_Store
bin/ameba
bin

2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ version: 2.0
shards:
ameba:
git: https://github.com/veelenga/ameba.git
version: 0.14.0
version: 1.1.0

2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: bindata
version: 1.10.0
version: 1.11.0
crystal: ">= 1.0.0"

development_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion spec/bitfield_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe BinData::BitField do
it "should raise an error when there is not enough data" do
io = IO::Memory.new
io.write_byte(0x80)

ex = expect_raises BinData::ParseError, "Failed to parse ByteSized.bitfield.header" do
io.read_bytes(ByteSized)
end
Expand Down
45 changes: 3 additions & 42 deletions src/bindata.cr
Original file line number Diff line number Diff line change
@@ -1,44 +1,7 @@
abstract class BinData
class CustomException < Exception
getter klass : String?
getter field : String?
getter field_type : String?

def initialize(message, ex : Exception)
super(message, ex)
end

def initialize(message)
super(message)
end
end

class VerificationException < CustomException; end

class WritingVerificationException < VerificationException
def initialize(@klass, @field, @field_type)
super("Failed to verify writing #{field_type} at #{klass}.#{field}")
end
end

class ReadingVerificationException < VerificationException
def initialize(@klass, @field, @field_type)
super("Failed to verify reading #{field_type} at #{klass}.#{field}")
end
end

class ParseError < CustomException
def initialize(@klass, @field, ex : Exception)
super("Failed to parse #{klass}.#{field}", ex)
end
end

class WriteError < CustomException
def initialize(@klass, @field, ex : Exception)
super("Failed to write #{klass}.#{field}", ex)
end
end
require "./bindata/exceptions"
require "./bindata/bitfield"

abstract class BinData
INDEX = [-1]
BIT_PARTS = [] of Nil
CUSTOM_TYPES = [] of BinData.class
Expand Down Expand Up @@ -519,5 +482,3 @@ abstract class BinData
property {{name.id}} : Bytes = {% if default %} {{default}}.to_slice {% else %} Bytes.new(0) {% end %}
end
end

require "./bindata/bitfield"
41 changes: 41 additions & 0 deletions src/bindata/exceptions.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
abstract class BinData
class CustomException < Exception
getter klass : String?
getter field : String?
getter field_type : String?

def initialize(message, ex : Exception)
super(message, ex)
end

def initialize(message)
super(message)
end
end

class VerificationException < CustomException; end

class WritingVerificationException < VerificationException
def initialize(@klass, @field, @field_type)
super("Failed to verify writing #{field_type} at #{klass}.#{field}")
end
end

class ReadingVerificationException < VerificationException
def initialize(@klass, @field, @field_type)
super("Failed to verify reading #{field_type} at #{klass}.#{field}")
end
end

class ParseError < CustomException
def initialize(@klass, @field, ex : Exception)
super("Failed to parse #{klass}.#{field}", ex)
end
end

class WriteError < CustomException
def initialize(@klass, @field, ex : Exception)
super("Failed to write #{klass}.#{field}", ex)
end
end
end

0 comments on commit f5b97a6

Please sign in to comment.