Errors¶
When Domo says no, crew-dcs raises an error. It does not hand you a failed response to check by hand. This page shows which errors you will meet, what is on them, and how to catch the one you expect.
First fix: upgrade the library¶
Upgrade crew-dcs to the latest version before you dig into an error. Domo changes its API without notice, and crew-dcs is patched often. See Install for how to upgrade.
The family tree¶
Every error crew-dcs raises is a kind of DomoError. You import it from
crew_dcs.base.exceptions.
DomoError the base: catches anything crew-dcs raises
├── AuthError sign-in or token problems
│ ├── InvalidCredentialsError (examples: there are more subclasses)
│ └── InvalidInstanceError
├── RouteError Domo answered, and the answer was a failure
│ ├── DatasetNotFoundError (examples: each route module adds its own)
│ ├── Dataset_GET_Error (one per route module, see below)
│ └── Dataset_CRUD_Error
├── TransportError no answer at all (network, DNS, timeout)
└── ClassError a problem inside a class, not in Domo's answer
Two more come from the engine under the routes, and also derive from DomoError:
GetDataError (Domo served a web page instead of data, which usually means a VPN or
IP allow-list is in the way) and LooperError. Import GetDataError from
crew_dcs.client.get_data.
Auth errors¶
InvalidCredentialsError means the token, or the username and password, was
refused. InvalidInstanceError means Domo refused the instance name, so check
the spelling of DOMO_INSTANCE. Both are in crew_dcs.routes.auth. You usually meet
them on your first auth.who_am_i() call. See
Authenticating to Domo.
Route errors and their names¶
Each route module has its own errors, named after the kind of call:
<Thing>_GET_Erroris for reading.Dataset_GET_Erroris a failed DataSet read.<Thing>_CRUD_Erroris for creating, updating or deleting. CRUD is short for create, read, update, delete.- Some errors name one specific case, such as
DatasetNotFoundError.
DatasetNotFoundError is raised only when Domo answers 404 with the body
"Not Found". Any other 404 raises Dataset_GET_Error.
This is a convention, not a rule. Modules mostly follow it, but not every one does,
so check the module's reference page for the errors it defines. For DataSets:
crew_dcs.routes.dataset.exceptions.
What is on an error¶
Print the error to see its message. It reads like this:
[ERROR] || entity: 0000-not-a-real-id || dataset - 0000-not-a-real-id not found || Resource not found (HTTP 404)
You can also read each part as an attribute:
| Attribute | What it holds |
|---|---|
e.status |
The HTTP status number, such as 404. |
e.message |
The message, in plain words. |
e.entity_id |
The id of the thing the call was about, such as the DataSet id. |
e.res |
The failed response, on route and auth errors. Its .response is what Domo sent, and .request_metadata.url is the address the call went to. |
Catch the error you expect¶
Catch the narrowest error that fits. That way a bug in your script is not hidden by a catch-all.
import asyncio
import os
from dotenv import load_dotenv
from crew_dcs.auth import DomoTokenAuth
from crew_dcs.base.exceptions import DomoError
from crew_dcs.routes import dataset as dataset_routes
from crew_dcs.routes.dataset import DatasetNotFoundError
load_dotenv()
async def main():
async with DomoTokenAuth(
domo_instance=os.environ["DOMO_INSTANCE"],
domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
) as auth:
try:
res = await dataset_routes.get_dataset_by_id(
dataset_id="0000-not-a-real-id", auth=auth
)
except DatasetNotFoundError as e:
# The one case we expected: this id does not exist.
print("No such DataSet:", e.entity_id, "- status", e.status)
print("Asked:", e.res.request_metadata.url)
except DomoError as e:
# Anything else crew-dcs raised. Show it and stop.
print("Something else went wrong:", e)
raise
else:
print(res.response["name"])
asyncio.run(main())
Order matters. Python checks the except lines from the top and uses the first
one that fits. Put the narrow error first and DomoError last.
Avoid except Exception: around a Domo call. It also swallows typing mistakes
in your own code.
See the request: debug_api¶
Add debug_api=True to a call to log the request it sends:
res = await dataset_routes.get_dataset_by_id(
dataset_id=dataset_id, auth=auth, debug_api=True
)
It logs the request and the response at the DEBUG level. Credentials are
masked and response bodies are never logged.
To see these log lines, turn DEBUG on first with
set_domolibrary_logger(min_level="DEBUG") (from crew_dcs.utils.logging). The
log lines are held back and printed when the async with DomoTokenAuth(...) block
ends, so a short script prints them before it exits. If your script does not use
async with, end it with await flush_logs() (also from
crew_dcs.utils.logging), which prints any log lines still being held back.
Check any ids or names in the log before you paste it into a bug report.
Where to look next¶
- The reference for
crew_dcs.base.exceptionslists every field onDomoError. - The auth errors are in
crew_dcs.routes.auth. - Terms such as "route" and "entity" are in the Glossary.
- How crew-dcs is organised shows which layer raises which error.
Stuck?¶
Upgrade first. If the error stays, ask in the DataCrew community Slack: datacrew.space/slack. Include the error text, the status, and the route you called. Leave out your token.