diff --git a/flatland/envs/rail_env.py b/flatland/envs/rail_env.py
index 2f6bf81374f015b40de949e129136310a4c2115a..2999554d332c7312a03fdec327a1ff1b2cd70b9e 100644
--- a/flatland/envs/rail_env.py
+++ b/flatland/envs/rail_env.py
@@ -731,11 +731,9 @@ class RailEnv(Environment):
                     with open(filename, "wb") as file_out:
                         file_out.write(self.get_full_state_dist_msg())
                 else:
-                    with open(filename, "wb") as file_out:
-                        file_out.write(self.get_full_state_msg())
+                    raise Exception("Unable to save distance map")
             else:
-                with open(filename, "wb") as file_out:
-                    file_out.write(self.get_full_state_msg())
+                raise Exception("Unable to save distance map")
         else:
             with open(filename,"wb") as file_out:
                 file_out.write(self.get_full_state_msg())