MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / randomFailure

Function randomFailure

run/jobs/index.js:51–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50// Throw an error based on fail rate
51const randomFailure = rate => {
52 rate = parseFloat(rate);
53 if (!rate || rate < 0 || rate > 1) {
54 console.warn(
55 `Invalid FAIL_RATE env var value: ${rate}. Must be a float between 0 and 1 inclusive.`
56 );
57 return;
58 }
59
60 const randomFailure = Math.random();
61 if (randomFailure < rate) {
62 throw new Error('Task failed.');
63 }
64};
65
66// Start script
67main().catch(err => {

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected