Add default error IDs everywhere else.

The idea here is to make sure all return points have the same type for
the error cases.  There's not really all that many, so they just go in
one patch.  Some of these could potentially turn into more specialized
errors later.
This commit is contained in:
Chris Lumens 2018-08-09 11:05:59 -04:00
parent b3bb438254
commit fd901c5e3f
2 changed files with 38 additions and 22 deletions

View File

@ -24,6 +24,9 @@ BAD_COMPOSE_TYPE = "BadComposeType"
# not convert into an integer.
BAD_LIMIT_OR_OFFSET = "BadLimitOrOffset"
# Returned from the API for all other errors from a /blueprints/* route.
BLUEPRINTS_ERROR = "BlueprintsError"
# Returned from the API for any other error resulting from /compose failing.
BUILD_FAILED = "BuildFailed"
@ -32,6 +35,13 @@ BUILD_FAILED = "BuildFailed"
# a build that is not yet done.
BUILD_IN_WRONG_STATE = "BuildInWrongState"
# Returned from the API when some file is requested that is not present - a log
# file, the compose results, etc.
BUILD_MISSING_FILE = "BuildMissingFile"
# Returned from the API for all other errors from a /compose/* route.
COMPOSE_ERROR = "ComposeError"
# Returned from the API when a blueprint name or other similar identifier is
# given that contains invalid characters.
INVALID_NAME = "InvalidName"
@ -40,6 +50,12 @@ INVALID_NAME = "InvalidName"
# what to compose.
MISSING_POST = "MissingPost"
# Returned from the API for all other errors from a /modules/* route.
MODULES_ERROR = "ModulesError"
# Returned from the API for all other errors from a /projects/* route.
PROJECTS_ERROR = "ProjectsError"
# Returned from the API when someone tries to modify an immutable system source.
SYSTEM_SOURCE = "SystemSource"

View File

@ -1139,7 +1139,7 @@ def v0_api(api):
with api.config["GITLOCK"].lock:
commits = take_limits(list_commits(api.config["GITLOCK"].repo, branch, filename), offset, limit)
except Exception as e:
errors.append("%s: %s" % (blueprint_name, str(e)))
errors.append({"id": BLUEPRINTS_ERROR, "msg": "%s: %s" % (blueprint_name, str(e))})
log.error("(v0_blueprints_changes) %s", str(e))
else:
blueprints.append({"name":blueprint_name, "changes":commits, "total":len(commits)})
@ -1173,7 +1173,7 @@ def v0_api(api):
workspace_write(api.config["GITLOCK"].repo, branch, blueprint)
except Exception as e:
log.error("(v0_blueprints_new) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": BLUEPRINTS_ERROR, "msg": str(e)}]), 400
else:
return jsonify(status=True)
@ -1195,7 +1195,7 @@ def v0_api(api):
delete_recipe(api.config["GITLOCK"].repo, branch, blueprint_name)
except Exception as e:
log.error("(v0_blueprints_delete) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": BLUEPRINTS_ERROR, "msg": str(e)}]), 400
else:
return jsonify(status=True)
@ -1220,7 +1220,7 @@ def v0_api(api):
workspace_write(api.config["GITLOCK"].repo, branch, blueprint)
except Exception as e:
log.error("(v0_blueprints_workspace) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": BLUEPRINTS_ERROR, "msg": str(e)}]), 400
else:
return jsonify(status=True)
@ -1242,7 +1242,7 @@ def v0_api(api):
workspace_delete(api.config["GITLOCK"].repo, branch, blueprint_name)
except Exception as e:
log.error("(v0_blueprints_delete_workspace) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": BLUEPRINTS_ERROR, "msg": str(e)}]), 400
else:
return jsonify(status=True)
@ -1292,7 +1292,7 @@ def v0_api(api):
tag_recipe_commit(api.config["GITLOCK"].repo, branch, blueprint_name)
except Exception as e:
log.error("(v0_blueprints_tag) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": BLUEPRINTS_ERROR, "msg": str(e)}]), 400
else:
return jsonify(status=True)
@ -1381,7 +1381,7 @@ def v0_api(api):
with api.config["GITLOCK"].lock:
blueprint = read_recipe_commit(api.config["GITLOCK"].repo, branch, blueprint_name)
except Exception as e:
errors.append("%s: %s" % (blueprint_name, str(e)))
errors.append({"id": BLUEPRINTS_ERROR, "msg": "%s: %s" % (blueprint_name, str(e))})
log.error("(v0_blueprints_freeze) %s", str(e))
# No blueprint found, skip it.
@ -1399,7 +1399,7 @@ def v0_api(api):
with api.config["YUMLOCK"].lock:
deps = projects_depsolve(api.config["YUMLOCK"].yb, projects, blueprint.group_names)
except ProjectsError as e:
errors.append("%s: %s" % (blueprint_name, str(e)))
errors.append({"id": BLUEPRINTS_ERROR, "msg": "%s: %s" % (blueprint_name, str(e))})
log.error("(v0_blueprints_freeze) %s", str(e))
blueprints.append({"blueprint": blueprint.freeze(deps)})
@ -1441,7 +1441,7 @@ def v0_api(api):
with api.config["GITLOCK"].lock:
blueprint = read_recipe_commit(api.config["GITLOCK"].repo, branch, blueprint_name)
except Exception as e:
errors.append("%s: %s" % (blueprint_name, str(e)))
errors.append({"id": BLUEPRINTS_ERROR, "msg": "%s: %s" % (blueprint_name, str(e))})
log.error("(v0_blueprints_depsolve) %s", str(e))
# No blueprint found, skip it.
@ -1458,7 +1458,7 @@ def v0_api(api):
with api.config["YUMLOCK"].lock:
deps = projects_depsolve(api.config["YUMLOCK"].yb, projects, blueprint.group_names)
except ProjectsError as e:
errors.append("%s: %s" % (blueprint_name, str(e)))
errors.append({"id": BLUEPRINTS_ERROR, "msg": "%s: %s" % (blueprint_name, str(e))})
log.error("(v0_blueprints_depsolve) %s", str(e))
# Get the NEVRA's of the modules and projects, add as "modules"
@ -1487,7 +1487,7 @@ def v0_api(api):
available = projects_list(api.config["YUMLOCK"].yb)
except ProjectsError as e:
log.error("(v0_projects_list) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": PROJECTS_ERROR, "msg": str(e)}]), 400
projects = take_limits(available, offset, limit)
return jsonify(projects=projects, offset=offset, limit=limit, total=len(available))
@ -1506,7 +1506,7 @@ def v0_api(api):
projects = projects_info(api.config["YUMLOCK"].yb, project_names.split(","))
except ProjectsError as e:
log.error("(v0_projects_info) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": PROJECTS_ERROR, "msg": str(e)}]), 400
if not projects:
msg = "one of the requested projects does not exist: %s" % project_names
@ -1529,7 +1529,7 @@ def v0_api(api):
deps = projects_depsolve(api.config["YUMLOCK"].yb, [(n, "*") for n in project_names.split(",")], [])
except ProjectsError as e:
log.error("(v0_projects_depsolve) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": PROJECTS_ERROR, "msg": str(e)}]), 400
if not deps:
msg = "one of the requested projects does not exist: %s" % project_names
@ -1644,7 +1644,7 @@ def v0_api(api):
log.info("Updating repository metadata after adding %s failed", source["name"])
update_metadata(yb)
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": PROJECTS_ERROR, "msg": str(e)}]), 400
return jsonify(status=True)
@ -1705,7 +1705,7 @@ def v0_api(api):
available = modules_list(api.config["YUMLOCK"].yb, module_names)
except ProjectsError as e:
log.error("(v0_modules_list) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": MODULES_ERROR, "msg": str(e)}]), 400
if module_names and not available:
msg = "one of the requested modules does not exist: %s" % module_names
@ -1728,7 +1728,7 @@ def v0_api(api):
modules = modules_info(api.config["YUMLOCK"].yb, module_names.split(","))
except ProjectsError as e:
log.error("(v0_modules_info) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": MODULES_ERROR, "msg": str(e)}]), 400
if not modules:
msg = "one of the requested modules does not exist: %s" % module_names
@ -1859,7 +1859,7 @@ def v0_api(api):
try:
uuid_cancel(api.config["COMPOSER_CFG"], uuid)
except Exception as e:
return jsonify(status=False, errors=["%s: %s" % (uuid, str(e))]),400
return jsonify(status=False, errors=[{"id": COMPOSE_ERROR, "msg": "%s: %s" % (uuid, str(e))}]),400
else:
return jsonify(status=True, uuid=uuid)
@ -1884,7 +1884,7 @@ def v0_api(api):
try:
uuid_delete(api.config["COMPOSER_CFG"], uuid)
except Exception as e:
errors.append("%s: %s" % (uuid, str(e)))
errors.append({"id": COMPOSE_ERROR, "msg": "%s: %s" % (uuid, str(e))})
else:
results.append({"uuid":uuid, "status":True})
return jsonify(uuids=results, errors=errors)
@ -1901,7 +1901,7 @@ def v0_api(api):
try:
info = uuid_info(api.config["COMPOSER_CFG"], uuid)
except Exception as e:
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": COMPOSE_ERROR, "msg": str(e)}]), 400
if info is None:
return jsonify(status=False, errors=[{"id": UNKNOWN_UUID, "msg": "%s is not a valid build uuid" % uuid}]), 400
@ -1987,7 +1987,7 @@ def v0_api(api):
# Make sure it really exists
if not os.path.exists(image_path):
return jsonify(status=False, errors=["Build %s is missing image file %s" % (uuid, image_name)]), 400
return jsonify(status=False, errors=[{"id": BUILD_MISSING_FILE, "msg": "Build %s is missing image file %s" % (uuid, image_name)}]), 400
# Make the image name unique
image_name = uuid + "-" + image_name
@ -2006,7 +2006,7 @@ def v0_api(api):
try:
size = int(request.args.get("size", "1024"))
except ValueError as e:
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": COMPOSE_ERROR, "msg": str(e)}]), 400
status = uuid_status(api.config["COMPOSER_CFG"], uuid)
if status is None:
@ -2016,4 +2016,4 @@ def v0_api(api):
try:
return Response(uuid_log(api.config["COMPOSER_CFG"], uuid, size), direct_passthrough=True)
except RuntimeError as e:
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": COMPOSE_ERROR, "msg": str(e)}]), 400