fix: wrap unpickle in try-catch

This commit is contained in:
Simen Kirkvik
2022-09-23 08:28:23 +02:00
parent 49c1c25ee5
commit 811192a481

View File

@@ -622,8 +622,10 @@ type ExtendedGrid(grid: IGrid) =
if IO.File.Exists fname then
let pickle = IO.File.ReadAllBytes fname
neighborIndex <-
binarySerializer.UnPickle<NeighborIndex> pickle
|> Some
try binarySerializer.UnPickle<NeighborIndex> pickle |> Some
with e ->
Log.Error $"ExtendedGrid.loadNeighborIndex unpickle exception: {e.Message}:\n{e}"
None
true
else
false
@@ -643,7 +645,11 @@ type ExtendedGrid(grid: IGrid) =
let binarySerializer = FsPickler.CreateBinarySerializer()
if IO.File.Exists fname then
let pickle = IO.File.ReadAllBytes fname
nodeTree <- binarySerializer.UnPickle<IdxTree> pickle |> Some
nodeTree <-
try binarySerializer.UnPickle<IdxTree> pickle |> Some
with e ->
Log.Error $"ExtendedGrid.loadNodeTree unpickle exception: {e.Message}:\n{e}"
None
true
else
false
@@ -663,7 +669,11 @@ type ExtendedGrid(grid: IGrid) =
let binarySerializer = FsPickler.CreateBinarySerializer()
if IO.File.Exists fname then
let pickle = IO.File.ReadAllBytes fname
elementTree <- binarySerializer.UnPickle<IdxTree> pickle |> Some
elementTree <-
try binarySerializer.UnPickle<IdxTree> pickle |> Some
with e ->
Log.Error $"ExtendedGrid.loadElementTree unpickle exception: {e.Message}:\n{e}"
None
true
else
false