Skip to content

fix: coerce int error_code to str to prevent proto serialization failure#3434

Merged
pingsutw merged 1 commit into
masterfrom
adil/error_code-exception-type
May 26, 2026
Merged

fix: coerce int error_code to str to prevent proto serialization failure#3434
pingsutw merged 1 commit into
masterfrom
adil/error_code-exception-type

Conversation

@AdilFayyaz
Copy link
Copy Markdown
Collaborator

Why are the changes needed?

When a user task raises a custom exception with a non-string error_code (e.g. an integer HTTP status code), flytekit passed it directly to protobuf's string code field, causing TypeError: bad argument type for built-in operation inside ContainerError.to_flyte_idl(). This hid the original actionable exception from the UI entirely.

What changes were proposed in this pull request?

  • FlyteUserRuntimeException.error_code now coerces int error codes to str instead of passing them raw to protobuf
  • None error codes fall back to the default "USER:RuntimeError" code
  • Any other unsupported type raises FlyteException with a clear message rather than producing a cryptic TypeError deep in serialization
  • Added unit tests covering str passthrough, int coercion, None fallback, and unsupported-type raise; added an integration test that exercises the full _dispatch_execute → to_flyte_idl() → ErrorDocument.from_flyte_idl() round-trip

How was this patch tested?

  • Run pytest tests/flytekit/unit/exceptions/test_user.py — covers all error_code coercion cases
  • Run pytest tests/flytekit/unit/bin/test_python_entrypoint.py::test_dispatch_execute_non_string_error_code_serializes_cleanly — integration test using a real task that raises an exception with error_code = 422, verifying the error file is written with code == "422" and the original exception message is preserved

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Signed-off-by: M. Adil Fayyaz <62440954+AdilFayyaz@users.noreply.github.com>
@AdilFayyaz AdilFayyaz requested a review from pingsutw May 26, 2026 20:41
@AdilFayyaz AdilFayyaz self-assigned this May 26, 2026
@AdilFayyaz AdilFayyaz added the bug Something isn't working label May 26, 2026
@pingsutw pingsutw merged commit 2223dff into master May 26, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants