Skip to content

Commit bd15d04

Browse files
Licenserampcode-com
andcommitted
fix(metrics): validate time conversion results before API calls
Add explicit || exit 1 and empty-string checks after range_to_rfc3339 and date calls. Prevents empty timestamps from reaching the API with confusing errors when time conversion fails silently. Thread: https://ampcode.com/threads/T-019c5138-6cb8-7769-a841-0cba5cb26fd1 Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019c5138-6cb8-7769-a841-0cba5cb26fd1
1 parent 89cf6ba commit bd15d04

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

scripts/axiom-metrics-discover

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,25 @@ if [[ -n "$RANGE" && ( -n "$START_TIME" || -n "$END_TIME" ) ]]; then
8484
fi
8585

8686
if [[ -n "$RANGE" ]]; then
87-
START_TIME=$(range_to_rfc3339 "$RANGE")
88-
END_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)
87+
START_TIME=$(range_to_rfc3339 "$RANGE") || exit 1
88+
END_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ) || exit 1
89+
if [[ -z "$START_TIME" || -z "$END_TIME" ]]; then
90+
echo "Error: Failed to compute time range from '$RANGE'." >&2
91+
exit 1
92+
fi
8993
elif [[ -n "$START_TIME" && -n "$END_TIME" ]]; then
9094
: # explicit start/end provided
9195
elif [[ -n "$START_TIME" || -n "$END_TIME" ]]; then
9296
echo "Error: Both --start and --end are required when specifying explicit times." >&2
9397
exit 1
9498
else
9599
# Default to 1h
96-
START_TIME=$(range_to_rfc3339 "1h")
97-
END_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)
100+
START_TIME=$(range_to_rfc3339 "1h") || exit 1
101+
END_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ) || exit 1
102+
if [[ -z "$START_TIME" || -z "$END_TIME" ]]; then
103+
echo "Error: Failed to compute default time range." >&2
104+
exit 1
105+
fi
98106
fi
99107

100108
# URL-encode a path segment

scripts/axiom-metrics-query

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ if [[ -n "$RANGE" && ( -n "$START_TIME" || -n "$END_TIME" ) ]]; then
116116
fi
117117

118118
if [[ -n "$RANGE" ]]; then
119-
START_TIME=$(range_to_rfc3339 "$RANGE")
120-
END_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)
119+
START_TIME=$(range_to_rfc3339 "$RANGE") || exit 1
120+
END_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ) || exit 1
121+
if [[ -z "$START_TIME" || -z "$END_TIME" ]]; then
122+
echo "Error: Failed to compute time range from '$RANGE'." >&2
123+
exit 1
124+
fi
121125
elif [[ -z "$START_TIME" || -z "$END_TIME" ]]; then
122126
echo "Error: Either (--start + --end) or --range is required." >&2
123127
exit 1

0 commit comments

Comments
 (0)