Skip to content

Conversation

@grundprinzip
Copy link
Contributor

@grundprinzip grundprinzip commented Oct 31, 2025

What changes were proposed in this pull request?

This PR converts several IllegalArgumentException and UnsupportedOperationException instances in the Spark Connect server to proper SparkException with structured error classes, ensuring consistent error propagation to clients.

Changes include:

  1. Added error class definitions in error-conditions.json:

    • INVALID_PARAMETER_VALUE.INTERRUPT_TYPE_TAG_REQUIRES_TAG
    • INVALID_PARAMETER_VALUE.INTERRUPT_TYPE_OPERATION_ID_REQUIRES_ID
    • INVALID_PARAMETER_VALUE.STREAMING_LISTENER_COMMAND_MISSING
    • INVALID_ARTIFACT_PATH
    • UNSUPPORTED_FEATURE.INTERRUPT_TYPE
  2. Updated service handlers:

    • SparkConnectInterruptHandler: Converted generic exceptions to SparkSQLException
    • SparkConnectAddArtifactsHandler: Converted to SparkRuntimeException for invalid paths
    • SparkConnectStreamingQueryListenerHandler: Converted to SparkSQLException
  3. Added test coverage in SparkConnectServiceE2ESuite

Why are the changes needed?

Previously, the Spark Connect server threw generic Java exceptions that:

  • Did not include structured error classes
  • Could not be properly categorized by clients
  • Provided less actionable error information
  • Were inconsistent with Spark's error handling standards

The error handling infrastructure (ErrorUtils.handleError) can only propagate error classes from SparkThrowable instances. Generic Java exceptions are converted to generic UNKNOWN errors, losing important context.

Does this PR introduce any user-facing change?

Yes, but only to improve error messages.

Before:
java.lang.IllegalArgumentException: INTERRUPT_TYPE_TAG requested, but no operation_tag provided.

After:
[INVALID_PARAMETER_VALUE.INTERRUPT_TYPE_TAG_REQUIRES_TAG] The value of parameter(s)
operation_tag in interrupt is invalid: INTERRUPT_TYPE_TAG requested, but no
operation_tag provided.

Clients can now parse structured error classes for better error handling and recovery.

How was this patch tested?

  1. Added new test cases in SparkConnectServiceE2ESuite:

    • test("Interrupt with TAG type without operation_tag throws proper error class")
    • test("Interrupt with OPERATION_ID type without operation_id throws proper error class")
  2. Manual verification of error class propagation through the gRPC layer

  3. All modified files pass Scala style checks

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Sonnet 4.5

@grundprinzip grundprinzip changed the title [CONNECT][SQL] Convert IllegalArgumentException to SparkException with proper error classes in Spark Connect server [SPARK-54128][CONNECT][SQL] Convert IllegalArgumentException to SparkException with proper error classes in Spark Connect server Nov 1, 2025
@grundprinzip grundprinzip force-pushed the SPARK-error-messages branch 3 times, most recently from 8f59403 to 2ac3c88 Compare November 1, 2025 13:21
…h proper error classes in Spark Connect server

This PR converts several IllegalArgumentException and UnsupportedOperationException
instances in the Spark Connect server to proper SparkException with structured
error classes, ensuring consistent error propagation to clients.

Changes include:
1. Added error class definitions in error-conditions.json:
   - INVALID_PARAMETER_VALUE.INTERRUPT_TYPE_TAG_REQUIRES_TAG
   - INVALID_PARAMETER_VALUE.INTERRUPT_TYPE_OPERATION_ID_REQUIRES_ID
   - INVALID_PARAMETER_VALUE.STREAMING_LISTENER_COMMAND_MISSING
   - INVALID_ARTIFACT_PATH
   - UNSUPPORTED_FEATURE.INTERRUPT_TYPE

2. Updated service handlers:
   - SparkConnectInterruptHandler: Converted generic exceptions to SparkSQLException
   - SparkConnectAddArtifactsHandler: Converted to SparkRuntimeException for invalid paths
   - SparkConnectStreamingQueryListenerHandler: Converted to SparkSQLException

3. Added test coverage in SparkConnectServiceE2ESuite

Previously, the Spark Connect server threw generic Java exceptions that:
- Did not include structured error classes
- Could not be properly categorized by clients
- Provided less actionable error information
- Were inconsistent with Spark's error handling standards

The error handling infrastructure (ErrorUtils.handleError) can only propagate
error classes from SparkThrowable instances. Generic Java exceptions are
converted to generic UNKNOWN errors, losing important context.

Yes, but only to improve error messages.

Before:
  java.lang.IllegalArgumentException: INTERRUPT_TYPE_TAG requested, but no operation_tag provided.

After:
  [INVALID_PARAMETER_VALUE.INTERRUPT_TYPE_TAG_REQUIRES_TAG] The value of parameter(s)
  operation_tag in interrupt is invalid: INTERRUPT_TYPE_TAG requested, but no
  operation_tag provided.

Clients can now parse structured error classes for better error handling and recovery.

1. Added new test cases in SparkConnectServiceE2ESuite:
   - test("Interrupt with TAG type without operation_tag throws proper error class")
   - test("Interrupt with OPERATION_ID type without operation_id throws proper error class")

2. Manual verification of error class propagation through the gRPC layer
3. All modified files pass Scala style checks

Generated-by: Claude Sonnet 4.5
Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, LGTM.

dongjoon-hyun pushed a commit that referenced this pull request Nov 3, 2025
…Exception with proper error classes in Spark Connect server

### What changes were proposed in this pull request?

This PR converts several IllegalArgumentException and UnsupportedOperationException instances in the Spark Connect server to proper SparkException with structured error classes, ensuring consistent error propagation to clients.

Changes include:
1. Added error class definitions in error-conditions.json:
   - INVALID_PARAMETER_VALUE.INTERRUPT_TYPE_TAG_REQUIRES_TAG
   - INVALID_PARAMETER_VALUE.INTERRUPT_TYPE_OPERATION_ID_REQUIRES_ID
   - INVALID_PARAMETER_VALUE.STREAMING_LISTENER_COMMAND_MISSING
   - INVALID_ARTIFACT_PATH
   - UNSUPPORTED_FEATURE.INTERRUPT_TYPE

2. Updated service handlers:
   - SparkConnectInterruptHandler: Converted generic exceptions to SparkSQLException
   - SparkConnectAddArtifactsHandler: Converted to SparkRuntimeException for invalid paths
   - SparkConnectStreamingQueryListenerHandler: Converted to SparkSQLException

3. Added test coverage in SparkConnectServiceE2ESuite

### Why are the changes needed?

Previously, the Spark Connect server threw generic Java exceptions that:
- Did not include structured error classes
- Could not be properly categorized by clients
- Provided less actionable error information
- Were inconsistent with Spark's error handling standards

The error handling infrastructure (ErrorUtils.handleError) can only propagate error classes from SparkThrowable instances. Generic Java exceptions are converted to generic UNKNOWN errors, losing important context.

### Does this PR introduce _any_ user-facing change?

Yes, but only to improve error messages.

Before:
  java.lang.IllegalArgumentException: INTERRUPT_TYPE_TAG requested, but no operation_tag provided.

After:
  [INVALID_PARAMETER_VALUE.INTERRUPT_TYPE_TAG_REQUIRES_TAG] The value of parameter(s)
  operation_tag in interrupt is invalid: INTERRUPT_TYPE_TAG requested, but no
  operation_tag provided.

Clients can now parse structured error classes for better error handling and recovery.

### How was this patch tested?

1. Added new test cases in SparkConnectServiceE2ESuite:
   - test("Interrupt with TAG type without operation_tag throws proper error class")
   - test("Interrupt with OPERATION_ID type without operation_id throws proper error class")

2. Manual verification of error class propagation through the gRPC layer
3. All modified files pass Scala style checks

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Sonnet 4.5

Closes #52818 from grundprinzip/SPARK-error-messages.

Authored-by: Martin Grund <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit a830dd2)
Signed-off-by: Dongjoon Hyun <[email protected]>
@dongjoon-hyun
Copy link
Member

Merged to master/4.1 for Apache Spark 4.1.0.

Thank you, @grundprinzip and @HyukjinKwon .

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.

3 participants