Skip to content

Commit

Permalink
enhance exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tienday committed Feb 1, 2024
1 parent 16018b1 commit 2533781
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion studio/app/optinist/microscopes/ND2Reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _load_file(self, data_file_path: str) -> object:
handle = self.__dll.Lim_FileOpenForReadUtf8(data_file_path.encode("utf-8"))

if handle is None:
raise FileNotFoundError(data_file_path)
raise FileNotFoundError(f"Open Error: {data_file_path}")

return (handle,)

Expand Down
16 changes: 9 additions & 7 deletions studio/app/optinist/microscopes/OIRReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,32 @@ def _init_library(self):
ida = self.__dll = lib.load_library(__class__.get_library_path())

# initialize sdk library
ida.Initialize()
ida_result = ida.Initialize()
if ida_result != IDA_Result.IDA_RESULT_SUCCESS:
raise Exception("IDA Initialize Error")

def _load_file(self, data_file_path: str) -> object:
ida = self.__dll

# Get Accessor
hAccessor = self.__hAccessor = ctypes.c_void_p()
ida.GetAccessor(data_file_path, ctypes.byref(hAccessor))
if not hAccessor:
raise Exception("GetAccessor Error: Please check the File path.")
ida_result = ida.GetAccessor(data_file_path, ctypes.byref(hAccessor))
if ida_result != IDA_Result.IDA_RESULT_SUCCESS or not hAccessor:
raise FileNotFoundError(f"IDA GetAccessor Error: {data_file_path}")

# Connect
ida.Connect(hAccessor)

# Open file
hFile = ctypes.c_void_p()
result = ida.Open(
ida_result = ida.Open(
hAccessor,
data_file_path,
IDA_OpenMode.IDA_OM_READ,
ctypes.byref(hFile),
)
if result != IDA_Result.IDA_RESULT_SUCCESS:
raise Exception("Open Error")
if ida_result != IDA_Result.IDA_RESULT_SUCCESS or not hFile:
raise FileNotFoundError(f"IDA Open Error: {data_file_path}")

# Get Group Handle
hGroup = ctypes.c_void_p()
Expand Down

0 comments on commit 2533781

Please sign in to comment.