Browse code

reraise errors with informative message when learned function raises

Closes #15.

Joseph Weston authored on 19/02/2018 15:50:34
Showing 1 changed files
... ...
@@ -147,7 +147,14 @@ class BlockingRunner(BaseRunner):
147 147
                                           return_when=first_completed)
148 148
                 for fut in done:
149 149
                     x = xs.pop(fut)
150
-                    y = fut.result()
150
+                    try:
151
+                        y = fut.result()
152
+                    except Exception as e:
153
+                        raise RuntimeError(
154
+                            'An error occured while evaluating '
155
+                            f'"{self.learner.function.__name__}({x})". '
156
+                            'See the top traceback for details.'
157
+                        ) from e
151 158
                     if do_log:
152 159
                         self.log.append(('add_point', x, y))
153 160
                     self.learner.add_point(x, y)
... ...
@@ -334,7 +341,14 @@ class AsyncRunner(BaseRunner):
334 341
                                              loop=self.ioloop)
335 342
                 for fut in done:
336 343
                     x = xs.pop(fut)
337
-                    y = fut.result()
344
+                    try:
345
+                        y = fut.result()
346
+                    except Exception as e:
347
+                        raise RuntimeError(
348
+                            'An error occured while evaluating '
349
+                            f'"{self.learner.function.__name__}({x})". '
350
+                            'See the top traceback for details.'
351
+                        ) from e
338 352
                     if do_log:
339 353
                         self.log.append(('add_point', x, y))
340 354
                     self.learner.add_point(x, y)