cuddly-jelly-27016
03/17/2025, 5:04 PM_ERROR_CODE attributes in our exceptions. These error codes are important for us for our several other services to know what they should do in different situations. For example, we use "USER:NotReady" to signal that a dependency for the workflow is not yet available, soft failing the workflow and retrying again at regular intervals until the dependency is available. This behaviour has stopped working since this PR.
When we raise an exception that has this custom _ERROR_CODE attribute defined from within a task, that exception is caught and a FlyteUserRuntimeException is raised from it, wrapping the original user-raised exception. See the following lines in `PythonTask.dispatch_execute()`: https://github.com/flyteorg/flytekit/blob/master/flytekit/core/base_task.py#L754-L761
Then, in _dispatch_execute() in entrypoint.py, the FlyteUserRuntimeException which was raised is caught. (see these lines in that file). However the error code that is propagated to the ContainerError is not the one that the user has defined in their exception which was raised in the task originally - it is the error_code attribute of the wrapping FlyteUserRuntimeException, which will always be set to "USER:RuntimeError".
As a result of this, _ERROR_CODE attributes that are defined in any user-raised Exception are not propagated; instead the error code that is propagated is always "USER:RuntimeError".
### Expected behavior
If a user-defined exception is raised, and if it defined an _ERROR_CODE attribute in any way at all, that error code should be propagated to the ContainerError, and if the raised Exception does not define any error code, then the `FlyteUserRuntimeException`'s default error code of "USER:RuntimeError" should be passed instead.
### Additional context to reproduce
Run a dummy task throwing any Exception that defines an _ERROR_CODE.
class CustomException(Exception):
_ERROR_CODE = "USER:DoSomething"
The error code that will get propagated to the ContainerError that is eventually raised will not be "USER:DoSomething", rather it will be "USER:RuntimeError" since that is the _ERROR_CODE of the wrapping FlyteUserRuntimeException.
### Screenshots
No response
### Are you sure this issue hasn't been raised already?
• Yes
### Have you read the Code of Conduct?
• Yes
flyteorg/flytecuddly-jelly-27016
03/17/2025, 6:23 PM