Skip to content

Commit 7b623bf

Browse files
Properly wrap exceptions from schedule client (#1827)
Wrap schedule exception
1 parent bf6ae4b commit 7b623bf

File tree

2 files changed

+75
-19
lines changed

2 files changed

+75
-19
lines changed

temporal-sdk/src/main/java/io/temporal/internal/client/RootScheduleClientInvoker.java

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public void createSchedule(CreateScheduleInput input) {
107107
} else {
108108
throw new ScheduleException(e);
109109
}
110+
} catch (Exception e) {
111+
throw new ScheduleException(e);
110112
}
111113
}
112114

@@ -153,7 +155,11 @@ public void backfillSchedule(BackfillScheduleInput input) {
153155
.setScheduleId(input.getScheduleId())
154156
.setPatch(patch)
155157
.build();
156-
genericClient.patchSchedule(request);
158+
try {
159+
genericClient.patchSchedule(request);
160+
} catch (Exception e) {
161+
throw new ScheduleException(e);
162+
}
157163
}
158164

159165
@Override
@@ -164,7 +170,11 @@ public void deleteSchedule(DeleteScheduleInput input) {
164170
.setNamespace(clientOptions.getNamespace())
165171
.setScheduleId(input.getScheduleId())
166172
.build();
167-
genericClient.deleteSchedule(request);
173+
try {
174+
genericClient.deleteSchedule(request);
175+
} catch (Exception e) {
176+
throw new ScheduleException(e);
177+
}
168178
}
169179

170180
@Override
@@ -175,16 +185,20 @@ public DescribeScheduleOutput describeSchedule(DescribeScheduleInput input) {
175185
.setScheduleId(input.getScheduleId())
176186
.build();
177187

178-
DescribeScheduleResponse response = genericClient.describeSchedule(request);
179-
return new DescribeScheduleOutput(
180-
new ScheduleDescription(
181-
input.getScheduleId(),
182-
scheduleRequestHeader.protoToScheduleInfo(response.getInfo()),
183-
scheduleRequestHeader.protoToSchedule(response.getSchedule()),
184-
Collections.unmodifiableMap(
185-
SearchAttributesUtil.decode(response.getSearchAttributes())),
186-
response.getMemo().getFieldsMap(),
187-
clientOptions.getDataConverter()));
188+
try {
189+
DescribeScheduleResponse response = genericClient.describeSchedule(request);
190+
return new DescribeScheduleOutput(
191+
new ScheduleDescription(
192+
input.getScheduleId(),
193+
scheduleRequestHeader.protoToScheduleInfo(response.getInfo()),
194+
scheduleRequestHeader.protoToSchedule(response.getSchedule()),
195+
Collections.unmodifiableMap(
196+
SearchAttributesUtil.decode(response.getSearchAttributes())),
197+
response.getMemo().getFieldsMap(),
198+
clientOptions.getDataConverter()));
199+
} catch (Exception e) {
200+
throw new ScheduleException(e);
201+
}
188202
}
189203

190204
@Override
@@ -198,8 +212,11 @@ public void pauseSchedule(PauseScheduleInput input) {
198212
.setScheduleId(input.getScheduleId())
199213
.setPatch(patch)
200214
.build();
201-
202-
genericClient.patchSchedule(request);
215+
try {
216+
genericClient.patchSchedule(request);
217+
} catch (Exception e) {
218+
throw new ScheduleException(e);
219+
}
203220
}
204221

205222
@Override
@@ -216,7 +233,11 @@ public void triggerSchedule(TriggerScheduleInput input) {
216233
.setScheduleId(input.getScheduleId())
217234
.setPatch(patch)
218235
.build();
219-
genericClient.patchSchedule(request);
236+
try {
237+
genericClient.patchSchedule(request);
238+
} catch (Exception e) {
239+
throw new ScheduleException(e);
240+
}
220241
}
221242

222243
@Override
@@ -230,7 +251,11 @@ public void unpauseSchedule(UnpauseScheduleInput input) {
230251
.setScheduleId(input.getScheduleId())
231252
.setPatch(patch)
232253
.build();
233-
genericClient.patchSchedule(request);
254+
try {
255+
genericClient.patchSchedule(request);
256+
} catch (Exception e) {
257+
throw new ScheduleException(e);
258+
}
234259
}
235260

236261
@Override
@@ -249,6 +274,10 @@ public void updateSchedule(UpdateScheduleInput input) {
249274
.setRequestId(UUID.randomUUID().toString())
250275
.setSchedule(scheduleRequestHeader.scheduleToProto(schedule.getSchedule()))
251276
.build();
252-
genericClient.updateSchedule(request);
277+
try {
278+
genericClient.updateSchedule(request);
279+
} catch (Exception e) {
280+
throw new ScheduleException(e);
281+
}
253282
}
254283
}

temporal-sdk/src/test/java/io/temporal/client/schedules/ScheduleTest.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ public void createSchedule() {
111111
try {
112112
handle.describe();
113113
Assert.fail();
114-
} catch (Exception e) {
114+
} catch (ScheduleException e) {
115115
}
116116
// Create a handle to a non-existent schedule, creating the handle should not throw
117117
// but any operations on it should.
118118
try {
119119
ScheduleHandle badHandle = client.getHandle(UUID.randomUUID().toString());
120120
badHandle.delete();
121121
Assert.fail();
122-
} catch (Exception e) {
122+
} catch (ScheduleException e) {
123123
}
124124
}
125125

@@ -167,6 +167,12 @@ public void pauseUnpauseSchedule() {
167167
Assert.assertEquals(false, description.getSchedule().getState().isPaused());
168168
// Cleanup schedule
169169
handle.delete();
170+
// Try to unpause a deleted schedule
171+
try {
172+
handle.unpause("");
173+
Assert.fail();
174+
} catch (ScheduleException e) {
175+
}
170176
}
171177

172178
@Test
@@ -221,6 +227,12 @@ public void triggerSchedule() {
221227
Assert.assertEquals(3, handle.describe().getInfo().getNumActions());
222228
// Cleanup schedule
223229
handle.delete();
230+
// Try to trigger a deleted schedule
231+
try {
232+
handle.trigger();
233+
Assert.fail();
234+
} catch (ScheduleException e) {
235+
}
224236
}
225237

226238
@Test
@@ -253,6 +265,15 @@ public void backfillSchedules() {
253265
waitForActions(handle, 15);
254266
// Cleanup schedule
255267
handle.delete();
268+
// Try to backfill a deleted schedule
269+
try {
270+
handle.backfill(
271+
Arrays.asList(
272+
new ScheduleBackfill(now.minusMillis(5500), now.minusMillis(2500)),
273+
new ScheduleBackfill(now.minusMillis(2500), now)));
274+
Assert.fail();
275+
} catch (ScheduleException e) {
276+
}
256277
}
257278

258279
@Test
@@ -356,6 +377,12 @@ public void describeSchedules() {
356377
Assert.assertEquals(schedule.getState(), description.getSchedule().getState());
357378
// Cleanup schedule
358379
handle.delete();
380+
// Try to describe a deleted schedule
381+
try {
382+
handle.describe();
383+
Assert.fail();
384+
} catch (ScheduleException e) {
385+
}
359386
}
360387

361388
@Test

0 commit comments

Comments
 (0)