api: sysroot: detect and handle artifact failures

BUG=b:255838545
TEST=run_tests

Change-Id: I11b9f366456fa2c78f4b113babd653735052e228
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3988684
Reviewed-by: Alex Klein <saklein@chromium.org>
Tested-by: Jack Neus <jackneus@google.com>
Commit-Queue: Jack Neus <jackneus@google.com>
Reviewed-by: Madeleine Hardt <hardtmad@google.com>
diff --git a/api/controller/artifacts.py b/api/controller/artifacts.py
index c658d16..5f601cd 100644
--- a/api/controller/artifacts.py
+++ b/api/controller/artifacts.py
@@ -116,14 +116,21 @@
 
     for get_res in get_res_list:
         for artifact_dict in get_res.artifact_dict:
+            kwargs = {}
+            # TODO(b/255838545): Remove the kwargs funkness when these fields
+            # have been added for all services.
+            if "failed" in artifact_dict:
+                kwargs["failed"] = artifact_dict.get("failed", False)
+                kwargs["failure_reason"] = artifact_dict.get("failure_reason")
             get_res.output_proto.artifacts.add(
                 artifact_type=artifact_dict["type"],
                 paths=[
                     common_pb2.Path(
                         path=x, location=common_pb2.Path.Location.OUTSIDE
                     )
-                    for x in artifact_dict["paths"]
+                    for x in artifact_dict.get("paths", [])
                 ],
+                **kwargs,
             )
     return controller.RETURN_CODE_SUCCESS