From c3cfa8915e2237ac71575d1bccb4cff4fbb1d81c Mon Sep 17 00:00:00 2001 From: "Han-Ru Chen (Future-Outlier)" Date: Thu, 16 Jan 2025 15:43:18 +0800 Subject: [PATCH] Improve Type Engine Error Msg (#3063) * update Signed-off-by: Future-Outlier * ficx Signed-off-by: Future-Outlier * update Signed-off-by: Future-Outlier * test Signed-off-by: Future-Outlier * update Signed-off-by: Future-Outlier * update Signed-off-by: Future-Outlier * udpate Signed-off-by: Future-Outlier * update Signed-off-by: Future-Outlier * update Signed-off-by: Future-Outlier * updatre Signed-off-by: Future-Outlier --------- Signed-off-by: Future-Outlier --- flytekit/core/type_engine.py | 11 ++++++++--- tests/flytekit/unit/core/test_type_hints.py | 9 ++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/flytekit/core/type_engine.py b/flytekit/core/type_engine.py index 29092035b7..2b4619540d 100644 --- a/flytekit/core/type_engine.py +++ b/flytekit/core/type_engine.py @@ -1518,9 +1518,14 @@ async def _literal_map_to_kwargs( TypeEngine.async_to_python_value(ctx, lm.literals[k], python_interface_inputs[k]) ) await asyncio.gather(*kwargs.values()) - except TypeTransformerFailedError as exc: - exc.args = (f"Error converting input '{k}' at position {i}:\n {exc.args[0]}",) - raise + except Exception as e: + raise TypeTransformerFailedError( + f"Error converting input '{k}' at position {i}:\n" + f"Literal value: {lm.literals[k]}\n" + f"Literal type: {literal_types}\n" + f"Expected Python type: {python_interface_inputs[k]}\n" + f"Exception: {e}" + ) kwargs = {k: v.result() for k, v in kwargs.items() if v is not None} return kwargs diff --git a/tests/flytekit/unit/core/test_type_hints.py b/tests/flytekit/unit/core/test_type_hints.py index 1074423baf..ec977020b0 100644 --- a/tests/flytekit/unit/core/test_type_hints.py +++ b/tests/flytekit/unit/core/test_type_hints.py @@ -1896,12 +1896,11 @@ def wf2(a: typing.Union[int, str]) -> typing.Union[int, str]: with pytest.raises( TypeError, - match=re.escape( - f"Error encountered while converting inputs of '{exec_prefix}tests.flytekit.unit.core.test_type_hints.t2':\n" - r" Cannot convert from Flyte Serialized object (Literal):" - ), + match=( + rf"Error encountered while converting inputs of '{exec_prefix}tests\.flytekit\.unit\.core\.test_type_hints\.t2':\n\s+Error converting input 'a' at position 0:" + ), ): - assert wf2(a="2") == "2" + wf2(a="2") # Removed assert as it was not necessary for the exception to be raised def test_optional_type():