From 5c377d64d3c8ab115e81ac90c633c02b841b491b Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Fri, 4 Mar 2022 09:42:27 +0100 Subject: [PATCH] osclib: Add an helpful error on failed attribute save It's stil throwing the exception but with some luck the user sees the error and acts. --- osclib/core.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/osclib/core.py b/osclib/core.py index d78774b4..9628311c 100644 --- a/osclib/core.py +++ b/osclib/core.py @@ -1,9 +1,9 @@ from collections import namedtuple -from datetime import datetime -from datetime import timezone +from datetime import datetime, timezone from dateutil.parser import parse as date_parse import re import socket +import logging from lxml import etree as ET from urllib.error import HTTPError @@ -452,7 +452,12 @@ def attribute_value_save(apiurl, project, name, value, namespace='OSRT', package # The OBS API of attributes is super strange, POST to update. url = makeurl(apiurl, list(filter(None, ['source', project, package, '_attribute']))) - http_POST(url, data=ET.tostring(root)) + try: + http_POST(url, data=ET.tostring(root)) + except HTTPError as e: + if e.code == 404: + logging.error(f"Saving attribute {namespace}:{name} to {project} failed. You may need to create the type on your instance.") + raise e def attribute_value_delete(apiurl, project, name, namespace='OSRT', package=None):