Skip to content

Commit 04ab47a

Browse files
committed
Raise a ROCrate::ReadException on attempt to read non-RO-Crate zip file
...Previously threw a cryptic `TypeError`
1 parent ed4b804 commit 04ab47a

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

lib/ro_crate/reader.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def self.read_zip(source, target_dir: Dir.mktmpdir)
8787

8888
# Traverse the unzipped directory to try and find the crate's root
8989
root_dir = detect_root_directory(target_dir)
90+
raise ROCrate::ReadException, "No metadata found!" unless root_dir
9091

9192
read_directory(root_dir)
9293
end
@@ -303,7 +304,7 @@ def self.extract_root_entity(entities)
303304
end
304305

305306
##
306-
# Finds an RO-Crate's root directory (where `ro-crate-metdata.json` is located) within a given directory.
307+
# Finds an RO-Crate's root directory (where `ro-crate-metadata.json` is located) within a given directory.
307308
#
308309
# @param source [String, ::File, Pathname] The location of the directory.
309310
# @return [Pathname, nil] The path to the root, or nil if not found.

test/fixtures/just_a_zip.zip

199 Bytes
Binary file not shown.

test/reader_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ class ReaderTest < Test::Unit::TestCase
358358
ROCrate::Reader.read(fixture_file('broken/missing_file'))
359359
end
360360
assert_include e.message, 'not found in crate: file1.txt'
361+
362+
e = check_exception(ROCrate::ReadException) do
363+
ROCrate::Reader.read(fixture_file('just_a_zip.zip').path)
364+
end
365+
assert_include e.message, 'No metadata found'
361366
end
362367

363368
test 'tolerates arcp identifier on root data entity (and missing hasPart)' do

0 commit comments

Comments
 (0)