Skip to content

Improve Misleading Error Message in ContentTooLongException#1239

Merged
l-trotta merged 1 commit into
elastic:mainfrom
raynigon:main
May 27, 2026
Merged

Improve Misleading Error Message in ContentTooLongException#1239
l-trotta merged 1 commit into
elastic:mainfrom
raynigon:main

Conversation

@raynigon
Copy link
Copy Markdown
Contributor

@raynigon raynigon commented May 26, 2026

Fixes #1238

Context

Repository: elastic/elasticsearch-java
Pull Request: #1239
Component: Content validation / Buffer management

Description

When an incoming data stream exceeds the configured maximum buffer limit, the client throws a ContentTooLongException. However, the error message incorrectly reports the size of the current incoming data chunk (src.limit()) instead of the total accumulated content length.

This results in a highly confusing error message for users and developers, as the reported "too long" content size often appears to be significantly smaller than the configured buffer limit, masking the actual reason the request failed.

Example Scenario

Configured Buffer Limit: 1,000,000 bytes

Current Buffer Length: 995,000 bytes

Incoming Chunk (src.limit()): 8,192 bytes

Actual Combined Length: 1,003,192 bytes (Exceeds limit)

Resulting Exception Message: > "entity content is too long [8192] for the configured buffer limit [1000000]"

This makes debugging difficult, as it implies a chunk of ~8KB somehow breached a ~1MB limit.
Expected Behavior

The exception message should report the total calculated content length that caused the threshold to be breached, making it entirely clear why the data stream was rejected.

Expected Exception Message:

"entity content is too long [1003192] for the configured buffer limit [1000000]"

Actual Behavior

The exception message only references the size of the final byte buffer chunk (src.limit()), completely failing to account for the data already stored in the buffer (buffer.length()).

@cla-checker-service
Copy link
Copy Markdown

cla-checker-service Bot commented May 26, 2026

💚 CLA has been signed

@raynigon raynigon marked this pull request as draft May 26, 2026 19:04
@raynigon raynigon marked this pull request as ready for review May 26, 2026 19:04
@raynigon raynigon closed this May 26, 2026
@raynigon raynigon reopened this May 26, 2026
Copy link
Copy Markdown
Contributor

@l-trotta l-trotta left a comment

Choose a reason for hiding this comment

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

nice catch, thank you! LGTM

@l-trotta l-trotta merged commit 459ae28 into elastic:main May 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Misleading Error Message in ContentTooLongException

2 participants