| 36 | 36 | | pendingFrom, |
| 37 | 37 | | pendingMigrations, |
| 38 | 38 | | readLive, |
| 39 | + | retryableDeploy, |
| 39 | 40 | | versionFrom, |
| 41 | + | wranglerError, |
| 40 | 42 | | } from "./cloudflare.mjs"; |
| 41 | 43 | | import { changedNames, parseCargoLock, parseNpmLock, reaches } from "./lockfiles.mjs"; |
| 42 | 44 | | import { decide, git, planJson, pool } from "./plan.mjs"; |
| ⋯ |
| 812 | 814 | | assert.equal(settle, null); |
| 813 | 815 | | assert.equal(called, false); |
| 814 | 816 | | }); |
| 817 | + | |
| 818 | + | // What a deploy said when Cloudflare's API failed under it: the reason is |
| 819 | + | // in the ✘ [ERROR] block, and the last lines are only the request's trace. |
| 820 | + | const API_FAILED = [ |
| 821 | + | "Uploaded g1t-runner (12.31 sec)", |
| 822 | + | "✘ [ERROR] A request to the Cloudflare API (/accounts/abc/workers/scripts/g1t-runner/versions) failed.", |
| 823 | + | "", |
| 824 | + | " Service unavailable [code: 10013]", |
| 825 | + | "", |
| 826 | + | " If you think this is a bug, please open an issue at: https://github.com/cloudflare/workers-sdk/issues/new/choose", |
| 827 | + | "", |
| 828 | + | ' "result": {', |
| 829 | + | ' "id": "g1t-runner",', |
| 830 | + | " GET /accounts/abc/workers/services/g1t-runner -> 200 OK", |
| 831 | + | " Cloudflare Ray ID: a49663530d5eebe3-SJC", |
| 832 | + | ].join("\n"); |
| 833 | + | |
| 834 | + | test("a failed wrangler command is reported by its error, not its trace", () => { |
| 835 | + | const said = wranglerError(API_FAILED); |
| 836 | + | assert.match(said, /^✘ \[ERROR\] A request to the Cloudflare API/); |
| 837 | + | assert.match(said, /Service unavailable \[code: 10013\]/); |
| 838 | + | // No error block: its last lines, as before. |
| 839 | + | assert.equal(wranglerError("one\ntwo\nthree", 2), "two\nthree"); |
| 840 | + | }); |
| 841 | + | |
| 842 | + | test("Cloudflare failing is tried again; a mistake in what is deployed is not", () => { |
| 843 | + | assert.equal(retryableDeploy(API_FAILED), true); |
| 844 | + | assert.equal(retryableDeploy("✘ [ERROR] Build failed with 1 error:\n src/index.ts:3:7: ERROR: Could not resolve \"./nope\""), false); |
| 845 | + | assert.equal(retryableDeploy("✘ [ERROR] Processing wrangler.jsonc configuration:\n - \"main\" is not a valid path"), false); |
| 846 | + | assert.equal(retryableDeploy("fetch failed: ECONNRESET"), true); |
| 847 | + | }); |