Skip to content

Commit b7ba4ef

Browse files
committed
explicitly handle no matches
1 parent a6c91b9 commit b7ba4ef

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/dirty-days-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@repo/mcp-common': minor
3+
---
4+
5+
add relative timeframe support for querying

packages/mcp-common/src/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ export function parseRelativeTime(input: string): number {
1616
const sign = cleanedInput.startsWith('-') ? -1 : 1
1717

1818
const timeStr = cleanedInput.slice(1) // Remove the sign
19-
const seconds = timeStr.match(/\d+[smhdw]/g)!.reduce((total, match) => {
19+
const matches = timeStr.match(/\d+[smhdw]/g)
20+
21+
if (!matches) {
22+
throw new Error(`This shouldn't ever happen, but no matches found in: ${timeStr}`)
23+
}
24+
25+
const seconds = matches.reduce((total, match) => {
2026
const value = parseInt(match)
2127
const unit = match.slice(-1) as keyof typeof units
2228

0 commit comments

Comments
 (0)