CHIMEFRB / datatrail-cli

CHIME/FRB Data Management CLI
https://chimefrb.github.io/datatrail-cli/
MIT License
2 stars 0 forks source link

[BUG] Uncaught exception in clear command #62

Closed MWSammons closed 6 months ago

MWSammons commented 7 months ago

When running the clear command, if a dataset name is given which does not correspond do a real dataset the result from the decoded request will be the string '"\'NoneType\' object has no attribute \'datasets\'"'. As a result the if statement on the last line below will yield the error TypeError: string indices must be integers, not 'str' and the command with error out.

    payload = {"name": dataset, "scope": scope}
    url = server + "/query/dataset/find"
    logger.debug(f"URL: {url}")
    try:
        r = requests.post(url, json=payload)
        dataset_locations = utilities.decode_response(r)  # type: ignore
    except ConnectionError:
        return "The Datatrail Central Server at CHIME at is not reachable!!!"
    # Build data paths.
    if dataset_locations["file_replica_locations"].get("minoc"):  # type: ignore

Suggest adding a check like this from similar function

if "object has no attribute" in policy_response and isinstance(
            files_response, str
        ):
            raise Exception(f"Could not find {dataset} {scope} in Datatrail.")

@tjzegmott unless this error is caught some other way I'm not aware of? If not I'll make the requisite changes.

tjzegmott commented 7 months ago

I think it makes sense to include some kind of check here.

But I can see this been a common check, so let's create a function for it and put that in the utilities directory.