Unverified Commit 5cc70512 authored by Nicola Soranzo's avatar Nicola Soranzo
Browse files

Add dict to exception raised when encoding metadata fails

Add the second part in the following traceback:

```
DEBUG    galaxy.metadata:__init__.py:93 setting metadata externally failed for HistoryDatasetAssociation 1: Traceback (most recent call last):
  File "/usr/users/ga002/soranzon/software/nsoranzo_galaxy/lib/galaxy/model/metadata.py", line 246, in to_JSON_dict
    encoded_meta_dict = galaxy.model.custom_types.json_encoder.encode(meta_dict)
  File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/users/ga002/soranzon/software/nsoranzo_galaxy/lib/galaxy/model/custom_types.py", line 39, in default
    return json.JSONEncoder.default(self, obj)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ndarray is not JSON serializable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/users/ga002/soranzon/software/nsoranzo_galaxy/lib/galaxy/metadata/set_metadata.py", line 334, in set_metadata_portable
    dataset.metadata.to_JSON_dict(filename_out)  # write out results of set_meta
  File "/usr/users/ga002/soranzon/software/nsoranzo_galaxy/lib/galaxy/model/metadata.py", line 248, in to_JSON_dict
    raise Exception(f"Failed encoding metadata dictionary: {meta_dict}") from e
Exception: Failed encoding metadata dictionary: {'dbkey': '?', 'title': None, 'description': None, 'url': None, 'doi': None, 'loom_spec_version': array([b'2.0.1'], dtype='|S6'), 'shape': (5, 10), 'layers
_count': 0, 'layers_names': [], 'row_attrs_count': 1, 'row_attrs_names': ['rownames'], 'col_attrs_count': 2, 'col_attrs_names': ['colnames', 'colnames_factor'], 'col_graphs_count': 0, 'col_graphs_names':
 [], 'row_graphs_count': 0, 'row_graphs_names': []}
```
parent 29153107
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -239,7 +239,10 @@ class MetadataCollection(Mapping):
            meta_dict['__validated_state__'] = dataset_meta_dict['__validated_state__']
        if '__validated_state_message__' in dataset_meta_dict:
            meta_dict['__validated_state_message__'] = dataset_meta_dict['__validated_state_message__']
        try:
            encoded_meta_dict = galaxy.model.custom_types.json_encoder.encode(meta_dict)
        except Exception as e:
            raise Exception(f"Failed encoding metadata dictionary: {meta_dict}") from e
        if filename is None:
            return encoded_meta_dict
        with open(filename, 'wt+') as fh: