Skip to content

Commit

Permalink
Raise a custom ValidationError, including the archives URI (if set).
Browse files Browse the repository at this point in the history
  • Loading branch information
jarib committed Jan 9, 2011
1 parent 82567d5 commit 26cdab3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/har/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def valid?

def validate!
JSON::Validator.validate2 schema_file, @input
rescue JSON::ValidationError => ex
# add archive uri to the message
if @uri
raise ValidationError, "#{@uri}: #{ex.message}"
else
raise ValidationError, ex.message
end
end

protected
Expand Down
2 changes: 1 addition & 1 deletion spec/har/archive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module HAR
end

it "raises an error if the archive is invalid" do
lambda { invalid.validate! }.should raise_error(JSON::ValidationError)
lambda { invalid.validate! }.should raise_error(ValidationError, /bad\.har/)
end
end

Expand Down

0 comments on commit 26cdab3

Please sign in to comment.