Skip to content

Commit 68ccb11

Browse files
authored
fix(client): Fix incorrect schedule spec boundaries (#1120)
Thanks to @florianmorath for reporting
1 parent a05a637 commit 68ccb11

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/client/src/schedule-client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ export class ScheduleClient extends BaseClient {
260260
const res = await this.workflowService.createSchedule(req);
261261
return { conflictToken: res.conflictToken };
262262
} catch (err: any) {
263+
if (err instanceof TypeError) throw err;
263264
if (err.code === grpcStatus.ALREADY_EXISTS) {
264265
throw new ScheduleAlreadyRunning('Schedule already exists and is running', opts.scheduleId);
265266
}
@@ -305,6 +306,7 @@ export class ScheduleClient extends BaseClient {
305306
requestId: uuid4(),
306307
});
307308
} catch (err: any) {
309+
if (err instanceof TypeError) throw err;
308310
this.rethrowGrpcError(err, scheduleId, 'Failed to update schedule');
309311
}
310312
}

packages/client/src/schedule-helpers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ const [encodeMinute, decodeMinue] = makeCalendarSpecFieldCoders(
6666

6767
const [encodeHour, decodeHour] = makeCalendarSpecFieldCoders(
6868
'hour',
69-
(x: number) => (typeof x === 'number' && x >= 0 && x <= 59 ? x : undefined),
69+
(x: number) => (typeof x === 'number' && x >= 0 && x <= 23 ? x : undefined),
7070
(x: number) => x,
7171
[{ start: 0, end: 0, step: 0 }], // default to 0
7272
[{ start: 0, end: 23, step: 1 }]
7373
);
7474

7575
const [encodeDayOfMonth, decodeDayOfMonth] = makeCalendarSpecFieldCoders(
7676
'dayOfMonth',
77-
(x: number) => (typeof x === 'number' && x >= 0 && x <= 6 ? x : undefined),
77+
(x: number) => (typeof x === 'number' && x >= 0 && x <= 31 ? x : undefined),
7878
(x: number) => x,
7979
[{ start: 1, end: 31, step: 1 }], // default to *
8080
[{ start: 1, end: 31, step: 1 }]
@@ -139,7 +139,7 @@ function makeCalendarSpecFieldCoders<Unit>(
139139
const value = encodeValueFn(item as Unit);
140140
if (value !== undefined) return { start: value, end: value, step: 1 };
141141
}
142-
throw new Error(`Invalid CalendarSpec component for field ${fieldName}: '${item}' of type '${typeof item}'`);
142+
throw new TypeError(`Invalid CalendarSpec component for field ${fieldName}: '${item}' of type '${typeof item}'`);
143143
});
144144
}
145145

@@ -349,7 +349,7 @@ export async function decodeScheduleAction(
349349
workflowTaskTimeout: optionalTsToMs(pb.startWorkflow.workflowTaskTimeout),
350350
};
351351
}
352-
throw new Error('Unsupported schedule action');
352+
throw new TypeError('Unsupported schedule action');
353353
}
354354

355355
export function decodeSearchAttributes(
@@ -397,7 +397,7 @@ export function decodeScheduleRecentActions(
397397
firstExecutionRunId: executionResult.startWorkflowResult!.runId!,
398398
},
399399
};
400-
} else throw new Error('Unsupported schedule action');
400+
} else throw new TypeError('Unsupported schedule action');
401401

402402
return {
403403
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

0 commit comments

Comments
 (0)