Repository: dandi/dandi-cli

Issue:
failed to extract metadata: UnboundLocalError: local variable 'value' referenced before assignment
When trying to upload a dataset, I get a number of errors regarding a local variable "value" and a failure to extract metadata. 

Traceback below

```
Traceback (most recent call last):
  File "/home/nrsc/.local/lib/python3.10/site-packages/dandi/upload.py", line 346, in process_path
    metadata = dfile.get_metadata(
  File "/home/nrsc/.local/lib/python3.10/site-packages/dandi/files/bases.py", line 484, in get_metadata
    metadata = nwb2asset(self.filepath, digest=digest)
  File "/home/nrsc/.local/lib/python3.10/site-packages/dandi/metadata/nwb.py", line 150, in nwb2asset
    asset_md = prepare_metadata(metadata)
  File "/home/nrsc/.local/lib/python3.10/site-packages/dandi/metadata/core.py", line 76, in prepare_metadata
    return extract_model(models.BareAsset, metadata)
  File "/home/nrsc/.local/lib/python3.10/site-packages/dandi/metadata/util.py", line 511, in extract_model
    value = kwargs.get(field, extract_field(field, metadata))
  File "/home/nrsc/.local/lib/python3.10/site-packages/dandi/metadata/util.py", line 628, in extract_field
    return FIELD_EXTRACTORS[field](metadata)
  File "/home/nrsc/.local/lib/python3.10/site-packages/dandi/metadata/util.py", line 522, in func
    m = extract_model(
  File "/home/nrsc/.local/lib/python3.10/site-packages/dandi/metadata/util.py", line 511, in extract_model
    value = kwargs.get(field, extract_field(field, metadata))
  File "/home/nrsc/.local/lib/python3.10/site-packages/dandi/metadata/util.py", line 628, in extract_field
    return FIELD_EXTRACTORS[field](metadata)
  File "/home/nrsc/.local/lib/python3.10/site-packages/dandi/metadata/util.py", line 477, in extract_species
    f"Cannot interpret species field: {value}. Please "
UnboundLocalError: local variable 'value' referenced before assignment

```
Any help would be appreciated.

Cheers,

Scott

Discussion:

Patch:
diff --git a/dandi/metadata/util.py b/dandi/metadata/util.py
index d3f8f95b..23f82b24 100644
--- a/dandi/metadata/util.py
+++ b/dandi/metadata/util.py
@@ -474,7 +474,7 @@ def extract_species(metadata: dict) -> models.SpeciesType | None:
                     break
         if value_id is None:
             raise ValueError(
-                f"Cannot interpret species field: {value}. Please "
+                f"Cannot interpret species field: {value_orig}. Please "
                 "contact help@dandiarchive.org to add your species. "
                 "You can also put the entire url from NCBITaxon "
                 "(http://www.ontobee.org/ontology/NCBITaxon) into "


Test patch:
diff --git a/dandi/tests/test_metadata.py b/dandi/tests/test_metadata.py
index 8c5229bd..415658e0 100644
--- a/dandi/tests/test_metadata.py
+++ b/dandi/tests/test_metadata.py
@@ -513,6 +513,12 @@ def test_species():
     }
 
 
+def test_extract_unknown_species():
+    with pytest.raises(ValueError) as excinfo:
+        extract_species({"species": "mumba-jumba"})
+    assert str(excinfo.value).startswith("Cannot interpret species field: mumba-jumba")
+
+
 def test_species_map():
     # all alternative names should be lower case
     for common_names, *_ in species_map: