Repository: dandi/dandi-cli

Issue:
validate: crashes if file is not read ok
```shell
(git-annex)lena:~/proj/dandi/nwb-datasets[master]bendichter/Gao2018
$> dandi validate *nwb           
anm00314746_2015-10-20 09:36:04 (1).nwb: ok
anm00314746_2015-10-21 11:25:41 (1).nwb: ok
anm00314746_2015-10-22 15:17:38 (1).nwb: ok
anm00314756_2015-10-20 19:42:11 (1).nwb: ok
anm00314756_2015-10-23 14:10:29 (1).nwb: ok
anm00314757_2015-10-20 17:37:31 (1).nwb: ok
anm00314757_2015-10-21 18:02:48 (1).nwb: ok
anm00314758_2015-10-20 10:49:30.nwb: ok
anm00314758_2015-10-21 10:10:14 (1).nwb: ok
anm00314758_2015-10-22 11:20:47 (1).nwb: ok
anm00314758_2015-10-23 09:49:01 (1).nwb: ok
anm00314760_2015-10-20 15:52:30.nwb: ok
anm00314760_2015-10-21 16:44:27.nwb: ok
anm00314760_2015-10-22 16:39:13 (1).nwb: ok
BAYLORCD12_2018-01-25 19:16:01.nwb: ok
BAYLORCD12_2018-01-26 12:25:06.nwb: ok
Error: Could not construct DynamicTableRegion object due to The index 63 is out of range for this DynamicTable of length 63

$> dandi --version             
0.4.4+7.g2f45a27.dirty
```

Discussion:

Patch:
diff --git a/dandi/validate.py b/dandi/validate.py
index a614bb7a..ff038262 100644
--- a/dandi/validate.py
+++ b/dandi/validate.py
@@ -51,7 +51,10 @@ def validate_dandi_nwb(filepath):
     """Provide validation of .nwb file regarding requirements we impose
     """
     # make sure that we have some basic metadata fields we require
-    meta = get_metadata(filepath)
+    try:
+        meta = get_metadata(filepath)
+    except BaseException as e:
+        return [f"Failed to read metadata: {e}"]
     return _check_required_fields(meta, _required_nwb_metadata_fields)
 
 


Test patch:
diff --git a/dandi/tests/test_validate.py b/dandi/tests/test_validate.py
index c125bdf8..5b350283 100644
--- a/dandi/tests/test_validate.py
+++ b/dandi/tests/test_validate.py
@@ -12,3 +12,15 @@ def test_validate_simple2(simple2_nwb):
     # this file should be ok
     errors = validate_file(simple2_nwb)
     assert not errors
+
+
+def test_validate_bogus(tmp_path):
+    path = tmp_path / "wannabe.nwb"
+    path.write_text("not really nwb")
+    # intended to produce use-case for https://github.com/dandi/dandi-cli/issues/93
+    # but it would be tricky, so it is more of a smoke test that
+    # we do not crash
+    errors = validate_file(str(path))
+    # ATM we would get 2 errors -- since could not be open in two places,
+    # but that would be too rigid to test. Let's just see that we have expected errors
+    assert any(e.startswith("Failed to read metadata") for e in errors)