Skip to content

Commit ecb4800

Browse files
committed
added exception handling
1 parent ea7e9a9 commit ecb4800

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/sagemaker/serializers.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import csv
1919
import io
2020
import json
21-
import os
2221
import numpy as np
2322
from six import with_metaclass
2423

@@ -381,10 +380,13 @@ def serialize(self, data):
381380
raw-bytes: The data serialized as a raw-bytes from the input.
382381
"""
383382
if isinstance(data, str):
384-
if not os.path.exists(data):
383+
try:
384+
dataFile = open(data, "rb")
385+
except Exception:
385386
raise ValueError(f"{data} is not a valid file path.")
386-
image = open(data, "rb")
387-
return image.read()
387+
dataFileInfo = dataFile.read()
388+
dataFile.close()
389+
return dataFileInfo
388390
if isinstance(data, bytes):
389391
return data
390392

0 commit comments

Comments
 (0)