blob: cbec8da49053dbf6bede619fb5ca2f85fe748058 [file] [log] [blame]
Daniel Arndt0a881a32023-07-04 18:54:42 -03001#######################################################################################
2# Copyright ETSI Contributors and Others.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17from temporalio.client import WorkflowFailureError
18
19
20def get_root_cause(exception: WorkflowFailureError) -> BaseException:
21 """Get the root cause of a WorkflowFailureError
22
23 Temporal nests the cause of an exception at each layer as it bubbles up in
24 the framework from activities and child workflows. This function will
25 return the root cause of the exception.
26 """
27 cause = getattr(exception, "cause", None)
28 while cause:
29 exception = cause
30 cause = getattr(exception, "cause", None)
31 return exception