Severson-Group / AMDC-Firmware

Embedded system code (C and Verilog) which runs the AMDC Hardware
http://docs.amdc.dev/firmware
BSD 3-Clause "New" or "Revised" License
31 stars 5 forks source link

Add a check to make sure the specified map file exists. #286

Closed mslaffin closed 1 year ago

mslaffin commented 1 year ago

This PR adds a check to ensure that a valid path to a folder with a mapfile.txt is passed to find_mapfile() before AMDC_Logger is initiated. If the specified path does not exist or the mapfile does not exist at this location, then an exception is raised. Previously no errors are shown if find_mapfile returns a null value.

Example scenarios where this check would be encountered

Passing a non-existent file path:

mfpath = find_mapfile(r'C:\Users\laffi\Documents\Grad_School\AMDC\my-AMDC-private-C-code\fakefolder') 
logger = AMDC_Logger(amdc, mfpath)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Input In [5], in <cell line: 2>()
      1 mfpath = find_mapfile(r'C:\Users\laffi\Documents\Grad_School\AMDC\my-AMDC-private-C-code\fakefolder') 
----> 2 logger = AMDC_Logger(amdc, mfpath)

File ~\Documents\Grad_School\AMDC\AMDC-Firmware\scripts\AMDC_Logger.py:27, in AMDC_Logger.__init__(self, AMDC, mapfile)
     24 def __init__(self, AMDC, mapfile):
     26     if mapfile == None:
---> 27         raise Exception("Could not find map file")
     29     self.amdc = AMDC
     30     self.mapfile = Mapfile(mapfile)

Exception: Could not find map file

Passing a valid file path which does not contain a mapfile

mfpath = find_mapfile(r'C:\Users\laffi\Documents\Grad_School\AMDC\my-AMDC-private-C-code\usr') 
logger = AMDC_Logger(amdc, mfpath)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Input In [5], in <cell line: 2>()
      1 mfpath = find_mapfile(r'C:\Users\laffi\Documents\Grad_School\AMDC\my-AMDC-private-C-code\usr') 
----> 2 logger = AMDC_Logger(amdc, mfpath)

File ~\Documents\Grad_School\AMDC\AMDC-Firmware\scripts\AMDC_Logger.py:27, in AMDC_Logger.__init__(self, AMDC, mapfile)
     24 def __init__(self, AMDC, mapfile):
     26     if mapfile == None:
---> 27         raise Exception("Could not find map file")
     29     self.amdc = AMDC
     30     self.mapfile = Mapfile(mapfile)

Exception: Could not find map file
npetersen2 commented 1 year ago

Also, please submit an issue to this repo which states the problem you are facing. Then, mark this PR as "resolving" that issue. This helps us track the code development.

npetersen2 commented 1 year ago

I changed your PR's base branch per the docs: https://docs.amdc.dev/firmware/development/

npetersen2 commented 1 year ago

Let's merge this in.

npetersen2 commented 1 year ago

Due to additional commits on this branch due to base not being develop, I am closing this PR and moving the change commit to #291