Skip to content

Conversation

@andresgomezfrr
Copy link
Contributor

@andresgomezfrr andresgomezfrr commented Nov 5, 2025

Tracking issue

Closes flyteorg/flyte#6719

Why are the changes needed?

The changes are needed to validate and access the error_code property of the metaclass properly.

Current:

from flytekit.exceptions.user import FlyteUserException

class Example(FlyteUserException):
  _ERROR_CODE = "USER:Example"

v = Example()
print(hasattr(v, "error_code")) # False

Proposed:

from flytekit.exceptions.user import FlyteUserException

class Example(FlyteUserException):
  _ERROR_CODE = "USER:Example"

v = Example()
print(hasattr(v.__class__, "error_code")) # True

How was this patch tested?

Above example

Summary by Bito

  • This pull request modifies the accessibility of the error_code property in the FlyteUserException class by changing its access from the instance to the metaclass, ensuring correct retrieval.
  • Modifies the retrieval method of the error_code property in the FlyteUserException class to enhance accessibility, resolving an issue with accessibility.
  • Updates tests to validate the new behavior of error_code retrieval.
  • Improves the overall reliability of error handling in the Flyte framework.
  • This change resolves a specific problem where the error_code was not accessible as expected, thus enhancing the reliability of error handling in the Flyte framework.
  • Overall summary: touches error handling in the Flyte framework and improves reliability.

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.51%. Comparing base (545d07e) to head (2a63313).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
flytekit/exceptions/user.py 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3349      +/-   ##
==========================================
- Coverage   47.70%   47.51%   -0.19%     
==========================================
  Files         216      216              
  Lines       22686    22625      -61     
  Branches     2971     2973       +2     
==========================================
- Hits        10822    10751      -71     
- Misses      11286    11300      +14     
+ Partials      578      574       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Andres Gomez Ferrer <[email protected]>
kumare3
kumare3 previously approved these changes Nov 7, 2025
@machichima
Copy link
Member

machichima commented Nov 10, 2025

Hi @andresgomezfrr ,
Just want to make sure what you want to achieve here. I tried running your example showed in the PR description on the master branch, and it gives the expected output as you showed.

from flytekit.exceptions.user import FlyteUserException, FlyteUserRuntimeException

class Example(FlyteUserException):
    _ERROR_CODE = "USER:Example"

v = Example()
print(type(v).error_code)   # USER:Example
print(hasattr(v, "error_code"))   # False
print(hasattr(v.__class__, "error_code"))   # True

Based on your changes, I think you are trying to get the custom error code when doing the following?

v = FlyteUserRuntimeException(Example())
print(v.error_code)  # Expected: USER:Example

Thank you!

@andresgomezfrr
Copy link
Contributor Author

Hi @andresgomezfrr , Just want to make sure what you want to achieve here. I tried running your example showed in the PR description on the master branch, and it gives the expected output as you showed.

from flytekit.exceptions.user import FlyteUserException, FlyteUserRuntimeException

class Example(FlyteUserException):
    _ERROR_CODE = "USER:Example"

v = Example()
print(type(v).error_code)   # USER:Example
print(hasattr(v, "error_code"))   # False
print(hasattr(v.__class__, "error_code"))   # True

Based on your changes, I think you are trying to get the custom error code when doing the following?

v = FlyteUserRuntimeException(Example())
print(v.error_code)  # Expected: USER:Example

Thank you!

Exactly the main reason is to get the proper error code. Currently if you check the master code:
https://github.com/flyteorg/flytekit/pull/3349/files#diff-4fe1bf14925335fc7bc5e5e01f51ccb5980680add97005d244b114d9e05f782dL34-L35
This always returns USER:RuntimeError which is not good

@andresgomezfrr
Copy link
Contributor Author

@machichima

I also updated this logic https://github.com/flyteorg/flytekit/pull/3349/files#diff-4fe1bf14925335fc7bc5e5e01f51ccb5980680add97005d244b114d9e05f782dR34-R39 to allow all the cases, the error_code could be defined at instance and it could be also defined in the class.

machichima
machichima previously approved these changes Nov 10, 2025
Copy link
Member

@machichima machichima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification! Could you please run make lint to solve the CI lint error?

@andresgomezfrr andresgomezfrr dismissed stale reviews from machichima and kumare3 via 6c4ead7 November 10, 2025 12:33
@andresgomezfrr
Copy link
Contributor Author

Thank you for the clarification! Could you please run make lint to solve the CI lint error?

done! :)

Signed-off-by: Andres Gomez Ferrer <[email protected]>
@machichima machichima merged commit 3645cb3 into flyteorg:master Nov 10, 2025
114 of 117 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Error code is not propagated properly from users exceptions

3 participants