Skip to content

misc: Add a new error code for remote function to be caught by try#26928

Closed
feilong-liu wants to merge 1 commit intoprestodb:masterfrom
feilong-liu:export-D90356706
Closed

misc: Add a new error code for remote function to be caught by try#26928
feilong-liu wants to merge 1 commit intoprestodb:masterfrom
feilong-liu:export-D90356706

Conversation

@feilong-liu
Copy link
Contributor

@feilong-liu feilong-liu commented Jan 9, 2026

Description

When running remote functions, error in one single function call can fail the whole query. Consider that remote functions is less stable than local functions, sometimes it makes sense to not fail the query if a few of the function calls fail.
This PR adds a new error code, which can be used in remote functions, so that users can opt in to not fail a query with the TRY function.

Motivation and Context

Give user the flexibility to not fail a query if a few remote function calls fail

Impact

As in description

Test Plan

simple change

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== NO RELEASE NOTES ==

@feilong-liu feilong-liu requested a review from a team as a code owner January 9, 2026 00:39
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Jan 9, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 9, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a new REMOTE_FUNCTION_ERROR_CAUGHT_BY_TRY standard error code and ensures TryFunction treats this error code as handled (i.e., swallowed) similarly to other user-level data errors.

Class diagram for updated StandardErrorCode and TryFunction handling

classDiagram
    class StandardErrorCode {
        <<enum>>
        +DIVISION_BY_ZERO
        +INVALID_CAST_ARGUMENT
        +INVALID_FUNCTION_ARGUMENT
        +NUMERIC_VALUE_OUT_OF_RANGE
        +REMOTE_FUNCTION_ERROR_CAUGHT_BY_TRY
        +toErrorCode() ErrorCode
    }

    class ErrorCode {
        +getCode() int
    }

    class PrestoException {
        -ErrorCode errorCode
        +getErrorCode() ErrorCode
    }

    class TryFunction {
        -propagateIfUnhandled(e PrestoException) void
    }

    StandardErrorCode --> ErrorCode : creates
    PrestoException --> ErrorCode : has
    TryFunction ..> PrestoException : uses
    TryFunction ..> StandardErrorCode : compares codes
Loading

File-Level Changes

Change Details Files
Introduce a dedicated standard error code for remote function failures that are intended to be caught by TRY and wire it into TRY's handled-error filtering logic.
  • Add REMOTE_FUNCTION_ERROR_CAUGHT_BY_TRY to the StandardErrorCode enum as a USER_ERROR with a unique numeric code and a comment indicating it is caught by TRY
  • Update TryFunction.propagateIfUnhandled to treat REMOTE_FUNCTION_ERROR_CAUGHT_BY_TRY as a non-propagated error alongside existing handled error codes
presto-spi/src/main/java/com/facebook/presto/spi/StandardErrorCode.java
presto-main-base/src/main/java/com/facebook/presto/operator/scalar/TryFunction.java

Possibly linked issues

  • #(no explicit number provided): PR adds a specific remote function error code handled by TRY, likely preventing the test crashes described in issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@feilong-liu feilong-liu changed the title Add a new error code for remote function to be caught by try misc: Add a new error code for remote function to be caught by try Jan 9, 2026
@feilong-liu feilong-liu requested a review from kaikalur January 9, 2026 00:43
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The growing chain of || checks in propagateIfUnhandled is getting harder to maintain; consider refactoring these error-code checks into a static Set or helper method so adding new handled error codes is less error-prone.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The growing chain of `||` checks in `propagateIfUnhandled` is getting harder to maintain; consider refactoring these error-code checks into a static `Set` or helper method so adding new handled error codes is less error-prone.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@kaikalur
Copy link
Contributor

kaikalur commented Jan 9, 2026

Does this also allow for wrapping the full exception trace from remote?

import static com.facebook.presto.spi.StandardErrorCode.INVALID_CAST_ARGUMENT;
import static com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;
import static com.facebook.presto.spi.StandardErrorCode.NUMERIC_VALUE_OUT_OF_RANGE;
import static com.facebook.presto.spi.StandardErrorCode.REMOTE_FUNCTION_ERROR_CAUGHT_BY_TRY;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the CAUGHT_BY_TRY suffix? Maybe better would be a general:

CATCHABLE_EXCEPTION

and have a class that can be subclassed so we can add more later if needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants