Wrap cloudpickle.dumps to provide better error message when the object is not serializable.
(obj: Any, error_msg: str)
| 19 | |
| 20 | |
| 21 | def pickle_dumps(obj: Any, error_msg: str): |
| 22 | """Wrap cloudpickle.dumps to provide better error message |
| 23 | when the object is not serializable. |
| 24 | """ |
| 25 | try: |
| 26 | return pickle.dumps(obj) |
| 27 | except (TypeError, ray.exceptions.OufOfBandObjectRefSerializationException) as e: |
| 28 | sio = io.StringIO() |
| 29 | inspect_serializability(obj, print_file=sio) |
| 30 | msg = f"{error_msg}:\n{sio.getvalue()}" |
| 31 | if isinstance(e, TypeError): |
| 32 | raise TypeError(msg) from e |
| 33 | else: |
| 34 | raise ray.exceptions.OufOfBandObjectRefSerializationException(msg) |
no test coverage detected
searching dependent graphs…