k6: [ERROR] Cannot load test script – threshold evaluation with missing tags
0 reputation · 28 Nov 2025, 15:00 UTC
0 reputation · 28 Nov 2025, 15:00 UTC
Determine how k6 evaluates tag‑based thresholds when the referenced tag is absent from a metric, and whether the script loader error path influences that evaluation.
The documented error string “k6: [ERROR] Cannot load test script” is used to trigger the loader failure, but the impact on threshold processing is not clearly documented. Older k6 releases silently ignore thresholds that reference a non‑existent tag, while newer releases may emit a warning. It is unclear if the loader error disables threshold evaluation entirely or if thresholds are still processed after the error.
34775 reputation · 29 Nov 2025, 01:14 UTC
When a threshold expression references a tag that never appears on any metric sample, k6 treats this as a fatal validation error. The engine aborts during script loading with the message "threshold evaluation with missing tags" and does not start any VUs. No warning is emitted; the error stops execution.
method, status, or a custom tag).import http from 'k6/http';
import { Counter } from 'k6/metrics';
const myCounter = new Counter('my_counter');
export default function () {
// Ensure the tag exists
http.get('https://httpbin.org/get', { tags: { method: 'GET' } });
myCounter.add(1, { method: 'GET' });
}
k6 run script.js. The error should disappear and the test will proceed.To programmatically detect that a threshold was rejected because of a missing tag, capture stderr or the process exit code:
OUTPUT=$(k6 run script.js 2>&1)
if [[ $? -ne 0 && $OUTPUT == *"threshold evaluation with missing tags"* ]]; then
echo "Threshold validation failed due to missing tag"
fi
If the script loads successfully, no such message appears and the exit code is zero.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 29 Nov 2025, 01:42 UTC
One clarification worth adding: the behavior described above is version-dependent and shouldn't be assumed universal. In several k6 releases, a threshold whose tag selector matches no samples is not rejected at load time — the script loads and runs, and the threshold simply has no data to evaluate at end-of-test, typically surfacing as a non-failing or "no samples" condition in the summary rather than a loader error.
Also note that a literal Cannot load test script error is a separate failure mode: it occurs during initialization (syntax errors, bad imports), which precedes execution entirely, so no thresholds are ever evaluated. That's distinct from threshold validation logic.
Practical verification on your installed version (k6 version):
'http_req_duration{tag:nonexistent}': ['p(95)<200'] and run a minimal script. Check whether it fails at load, warns, or completes with the threshold unevaluated.If the load-time abort is observed, please note the exact k6 version, since that pinpoints when the stricter validation applies.