Skip to content

Conversation

@wgzhao
Copy link
Contributor

@wgzhao wgzhao commented Dec 17, 2025

What changes were proposed in this pull request?

This PR improves the error message in the TypeDescription.withPrecision(int precision) method. The previous error message incorrectly stated precision {value} is out of range 1 .. {scale} when the scale was greater than precision, which was misleading because it suggested the scale value was the upper bound for precision.

The new error message clearly states: the scale {scale} must be less than or equal to precision {precision}, which accurately describes the actual constraint violation.

Why are the changes needed?

The previous error message was confusing and misleading. When users encountered a case where scale > precision (e.g., precision=5, scale=10), the error message "precision 5 is out of range 1 .. 10" incorrectly suggested that precision must be between 1 and 10, when the real issue was that scale (10) cannot be greater than precision (5).

This improvement enhances the developer experience by providing a clear, accurate error message that directly points to the actual problem, making it easier to diagnose and fix the issue without needing to examine the source code.

How was this patch tested?

The existing test suite should validate this change. The modification only affects the error message text and does not change the validation logic itself. The same conditions that trigger the exception will continue to do so, but with a clearer message.

To verify the change manually:

  1. Create a TypeDescription with decimal type
  2. Set scale to a value (e.g., 10)
  3. Attempt to set precision to a value less than scale (e.g., 5)
  4. Verify the new error message is clear and accurate

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

No

Try to address the issue #2430

@github-actions github-actions bot added the JAVA label Dec 17, 2025
The previous error message "precision X is out of range 1 .. Y" was
misleading when scale > precision. It incorrectly suggested that Y
(scale) was the upper bound for precision, when the actual issue was
that scale must be less than or equal to precision.

Changed the error message to clearly state: "the scale X must be less
than or equal to precision Y" to accurately describe the constraint
violation and improve developer experience.
@wgzhao wgzhao force-pushed the improve_exception_message branch from 1637047 to c677f6a Compare December 17, 2025 07:22
Copy link
Contributor

@ffacs ffacs left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves error messages in the TypeDescription.withPrecision() method to make validation failures clearer. The previous error message incorrectly suggested that the scale value was the upper bound for precision when scale > precision. The new implementation separates the validation logic into distinct checks with more descriptive error messages.

  • Split the compound validation condition into two separate checks for better clarity
  • Improved error message for precision range validation to explicitly state the valid range (1 to MAX_PRECISION)
  • Improved error message for scale vs precision validation to clearly indicate that scale must be less than or equal to precision

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@wgzhao
Copy link
Contributor Author

wgzhao commented Dec 22, 2025

@cxzl25 @ffacs could you merge this PR ?

@ffacs ffacs closed this in ad5e7cf Dec 22, 2025
@ffacs
Copy link
Contributor

ffacs commented Dec 22, 2025

Thanks @wgzhao @cxzl25 ~

@ffacs ffacs reopened this Dec 22, 2025
@ffacs
Copy link
Contributor

ffacs commented Dec 22, 2025

The jira issue is not created, let me remove this patch first.

@ffacs ffacs changed the title ORC-2430: Improve error message in TypeDescription.withPrecision() ORC-2038: Improve error message in TypeDescription.withPrecision() Dec 22, 2025
@ffacs ffacs closed this in b11fa74 Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants