From 01c3000ef3962a2c4ab3d1a13b70df15f4370081 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Mon, 25 Jun 2018 10:50:30 +0100 Subject: [PATCH] master: Print offending key on HDF5 dataset type error This helps debugging the cause of TypeErrors arising from types not handled by the HDF5 serializer, as the backtrace doesn't otherwise include any useful information. --- artiq/master/worker_db.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/artiq/master/worker_db.py b/artiq/master/worker_db.py index d2dd628f5..3a3f7ef25 100644 --- a/artiq/master/worker_db.py +++ b/artiq/master/worker_db.py @@ -173,8 +173,18 @@ class DatasetManager: def write_hdf5(self, f): datasets_group = f.create_group("datasets") for k, v in self.local.items(): - datasets_group[k] = v + _write(datasets_group, k, v) archive_group = f.create_group("archive") for k, v in self.archive.items(): - archive_group[k] = v + _write(archive_group, k, v) + + +def _write(group, k, v): + # Add context to exception message when the user writes a dataset that is + # not representable in HDF5. + try: + group[k] = v + except TypeError as e: + raise TypeError("Error writing dataset '{}' of type '{}': {}".format( + k, type(v), e))