pepkit / pepdbagent

Database for storing sample metadata
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

Trying to Fetch Project that Doesnt Exist throws Error #8

Closed nleroy917 closed 1 year ago

nleroy917 commented 1 year ago

I'm integrating PepAgent into pephub and if I try to access a project that doesn't exist (e.g. demo/basiccc) then it throws a TypeError:

line 114, in get_project
    _LOGGER.info(f"Project has been found: {found_prj[0]}")
TypeError: 'NoneType' object is not subscriptable

Would be nice to have a simple catch and throw an error maybe? Or throw warning and just return the None

if found_prj is not None:
    _LOGGER.info(f"Project has been found: {found_prj[0]}")
    project_value = found_prj[1]

    new_project = peppy.Project()
    new_project.from_dict(project_value)

     return new_project
else:
    _LOGGER.warn(f"No project named '{project_name}' found in database.")
    return None

    # or throw exception?
    # raise pepagent.PEPNotFoundException(f"PEP with name '{project_name}' not found in database")

This helps me catch errors too on the PEPhub side of things so I can return 404's. Instead of looking for TypeErrors

nsheff commented 1 year ago

I agree this is a good idea. I have a slight preference for the warn/None option

nleroy917 commented 1 year ago

I'm getting a new error at line 174. If the PEP doesn't exist, it trys to coerce a None to a list, which doesn't work.

TypeError: 'NoneType' object is not iterable

Maybe a better way is to just place it in a list?

return [output_result]