apache/beam · error · NoSuchElementException
Failed to list first page of HL7v2 messages from %s: %s
Error message
Failed to list first page of HL7v2 messages from %s: %s
What it means
HL7v2MessagePages (the paginator for HL7v2IO list operations) fetches the first page of messages when hasNext() is first called. If that initial page request throws IOException, the paginator converts it into NoSuchElementException describing the failed first-page listing for the store, since pagination APIs cannot signal checked exceptions.
Source
Thrown at sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java:868
this.filter = filter;
this.orderBy = orderBy;
this.pageToken = null;
this.isFirstRequest = true;
}
@Override
public boolean hasNext() throws NoSuchElementException {
if (isFirstRequest) {
try {
ListMessagesResponse response =
makeListRequest(client, hl7v2Store, start, end, filter, orderBy, pageToken);
List<Message> msgs = response.getHl7V2Messages();
if (msgs == null) {
return false;
}
return !msgs.isEmpty();
} catch (IOException e) {
throw new NoSuchElementException(
String.format(
"Failed to list first page of HL7v2 messages from %s: %s",
hl7v2Store, e.getMessage()));
}
}
return this.pageToken != null;
}
@Override
public List<HL7v2Message> next() throws NoSuchElementException {
try {
ListMessagesResponse response =
makeListRequest(client, hl7v2Store, start, end, filter, orderBy, pageToken);
this.isFirstRequest = false;
this.pageToken = response.getNextPageToken();
List<Message> msgs = response.getHl7V2Messages();
return msgs.stream().map(HL7v2Message::fromModel).collect(Collectors.toList());View on GitHub (pinned to 12126d8942)
Solutions
- Verify the HL7v2 store resource path exists and the credentials have healthcare.hl7V2Stores.list permission.
- Inspect the cause chain: the NoSuchElementException message embeds the original IOException message — fix that root cause.
- Add retry with backoff around iteration start, or pre-fetch the first page yourself to control error handling.
- Catch NoSuchElementException where the paginator is consumed and treat it as a listing failure (alert/dead-letter) rather than 'end of data'.
Example fix
// before
Iterator<Message> it = HL7v2MessagePages.create(client, store, filter).iterator();
// NoSuchElementException on first page if API fails
// after
try {
Iterator<Message> it = HL7v2MessagePages.create(client, store, filter).iterator();
while (it.hasNext()) process(it.next());
} catch (NoSuchElementException e) {
LOG.error("First-page listing failed: {}", e.getMessage(), e);
} Defensive patterns
Strategy: retry
Validate before calling
// pre-validate store path before paginating
if (!store.matches("projects/[^/]+/locations/[^/]+/datasets/[^/]+/hl7V2Stores/[^/]+")) {
throw new IllegalArgumentException("Invalid HL7v2 store path: " + store);
} Try / catch
try {
HL7v2MessagePages pages = HL7v2MessagePages.create(client, store, filter);
// iterate
} catch (NoSuchElementException e) {
LOG.error("First-page listing from {} failed: {}", store, e.getMessage(), e);
// retry with backoff or surface as pipeline failure
} Prevention
- Validate the store resource path and IAM permissions before listing.
- Add retry/backoff around pagination start for transient API errors.
- Treat NoSuchElementException from the paginator as a listing failure, not end-of-data.
When it happens
Trigger: Iterating HL7v2MessagePages whose first listMessages call on the HL7v2 store throws IOException — network failure, invalid store path, permission denied, or API error on the initial page request.
Common situations: Wrong or nonexistent hl7v2Store resource path in configuration; missing healthcare.viewer IAM permissions; transient network/API outages when the paginator is first advanced; quota exhaustion on the list API.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- GET request for %s returned null
- Couldn't find message: %s.
- The PCollection tuple must have the HL7v2IO.Read.OUT and HL7
- The PCollection tuple must have the HL7v2IO.HL7v2Read.OUT an
- The batch import API is not supported yet
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/1dfcc4d32ee2955f.
Report an issue: GitHub.