Skip to content

Commit

Permalink
Add ticket content to error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 26, 2023
1 parent 18c96ff commit b5ba62b
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,20 @@ public void getStream(CallContext context, Ticket ticket, ServerStreamListener l
EndpointStatus status = statuses.get(index);
if (status.cancelled) {
listener.error(CallStatus.NOT_FOUND
.withDescription("Invalid flight: cancelled")
.withDescription("Invalid flight: cancelled: " +
new String(ticket.getBytes(), StandardCharsets.UTF_8))
.toRuntimeException());
return;
} else if (status.expirationTime != null && Instant.now().isAfter(status.expirationTime)) {
listener.error(CallStatus.NOT_FOUND
.withDescription("Invalid flight: expired")
.withDescription("Invalid flight: expired: " +
new String(ticket.getBytes(), StandardCharsets.UTF_8))
.toRuntimeException());
return;
} else if (status.expirationTime == null && status.numGets > 0) {
listener.error(CallStatus.NOT_FOUND
.withDescription("Invalid flight: can't read multiple times")
.withDescription("Invalid flight: can't read multiple times: " +
new String(ticket.getBytes(), StandardCharsets.UTF_8))
.toRuntimeException());
return;
}
Expand Down Expand Up @@ -157,7 +160,7 @@ public void doAction(CallContext context, Action action, StreamListener<Result>
EndpointStatus status = statuses.get(index);
if (status.cancelled) {
listener.onError(CallStatus.INVALID_ARGUMENT
.withDescription("Invalid flight: cancelled")
.withDescription("Invalid flight: cancelled: " + index)
.toRuntimeException());
return;
}
Expand Down Expand Up @@ -191,7 +194,7 @@ public void listActions(CallContext context, StreamListener<ActionType> listener
}

private FlightEndpoint addEndpoint(String ticket, Instant expirationTime) {
Ticket flightTicket = new Ticket(String.format("%d:%s", statuses.size(), ticket).getBytes(StandardCharsets.UTF_8));
Ticket flightTicket = new Ticket(String.format("%d: %s", statuses.size(), ticket).getBytes(StandardCharsets.UTF_8));
statuses.add(new EndpointStatus(expirationTime));
return new FlightEndpoint(flightTicket, expirationTime);
}
Expand All @@ -200,7 +203,10 @@ private int parseIndexFromTicket(Ticket ticket) {
final String contents = new String(ticket.getBytes(), StandardCharsets.UTF_8);
int index = contents.indexOf(':');
if (index == -1) {
throw CallStatus.INVALID_ARGUMENT.withDescription("Invalid ticket").toRuntimeException();
throw CallStatus.INVALID_ARGUMENT
.withDescription("Invalid ticket: " +
new String(ticket.getBytes(), StandardCharsets.UTF_8))
.toRuntimeException();
}
int endpointIndex = Integer.parseInt(contents.substring(0, index));
if (endpointIndex < 0 || endpointIndex >= statuses.size()) {
Expand Down

0 comments on commit b5ba62b

Please sign in to comment.