diff --git a/vermeer-python-client/src/pyvermeer/structure/task_data.py b/vermeer-python-client/src/pyvermeer/structure/task_data.py index 4cf0aa227..c245df6a0 100644 --- a/vermeer-python-client/src/pyvermeer/structure/task_data.py +++ b/vermeer-python-client/src/pyvermeer/structure/task_data.py @@ -62,6 +62,7 @@ def __init__(self, dic): self.__type = dic.get("type", "") self.__params = dic.get("params", {}) self.__workers = [TaskWorker(w) for w in dic.get("workers", [])] + self.__error_message = dic.get("error_message", "") @property def id(self) -> int: @@ -123,6 +124,11 @@ def workers(self) -> list[TaskWorker]: """task workers""" return self.__workers + @property + def error_message(self) -> str: + """task error message""" + return self.__error_message + def to_dict(self) -> dict: """to dict""" return { @@ -139,6 +145,7 @@ def to_dict(self) -> dict: "type": self.__type, "params": self.__params, "workers": [w.to_dict() for w in self.__workers], + "error_message": self.__error_message, } diff --git a/vermeer-python-client/src/tests/structure/test_task_data.py b/vermeer-python-client/src/tests/structure/test_task_data.py new file mode 100644 index 000000000..f1478ba5b --- /dev/null +++ b/vermeer-python-client/src/tests/structure/test_task_data.py @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from pyvermeer.structure.task_data import TaskInfo + + +def test_task_info_preserves_error_message(): + task = TaskInfo({"error_message": "task failed"}) + + assert task.error_message == "task failed" + assert task.to_dict()["error_message"] == "task failed" + + +def test_task_info_defaults_missing_error_message_to_empty_string(): + task = TaskInfo({"status": "success", "state": "success"}) + + assert task.error_message == "" + assert task.to_dict()["error_message"] == ""