windmill-labs/windmill · error
Preview failed: ${response.status} - ${response.statusText}
Error message
Preview failed: ${response.status} - ${response.statusText} - ${await response.text()} What it means
The preview command POSTs a form to the instance's preview/app endpoint. If the HTTP response is not ok, the CLI throws 'Preview failed' embedding the status code, status text, and response body via `detectAuthGatewayChallenge` having already checked for auth-gateway interception. This surfaces server-side validation or auth failures from the raw HTTP layer.
Source
Thrown at cli/src/commands/script/script.ts:2053
workspace.remote +
"api/w/" +
workspace.workspaceId +
"/jobs/run/preview_bundle";
const extraHeaders = getHeaders();
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${workspace.token}`,
...extraHeaders,
},
body: form,
});
await detectAuthGatewayChallenge(response, url);
if (!response.ok) {
throw new Error(
`Preview failed: ${response.status} - ${response.statusText} - ${await response.text()}`
);
}
const jobId = await response.text();
if (!opts.silent) {
await track_job(workspace.workspaceId, jobId);
}
// Wait for the job to complete and get the result
while (true) {
try {
const completedJob = await wmill.getCompletedJob({
workspace: workspace.workspaceId,
id: jobId,
});
const result = completedJob.result ?? {};View on GitHub (pinned to e474e8803c)
Solutions
- Read the status and body in the message: 401/403 → re-login with `wmill login` or refresh the token.
- 400 → fix the script error reported in the response body.
- Verify the instance URL and workspace with `wmill workspace show`.
- If behind a gateway/proxy, check its logs; 502/503 means the instance or upstream is down.
Example fix
// before wmill script preview f/my_script.py # 401 from expired token // after wmill login wmill script preview f/my_script.py
Defensive patterns
Strategy: try-catch
Validate before calling
const cfg = JSON.parse(readFileSync(configPath, 'utf8'));
const res = await fetch(cfg.baseUrl + '/api/version');
if (!res.ok) console.error('Instance unreachable or auth issue before preview'); Try / catch
try {
await wmill.script.preview(file, opts);
} catch (e) {
const m = String(e.message).match(/Preview failed: (\d+)/);
if (m) {
const status = Number(m[1]);
if (status === 401 || status === 403) console.error('Re-authenticate: wmill login');
else if (status >= 500) console.error('Server-side issue; check instance/proxy health.');
}
throw e;
} Prevention
- Refresh credentials (`wmill login`) before long CI sessions.
- Validate script syntax locally (lint/format) before previewing.
- Confirm `--base-url`/workspace points at the intended instance, especially behind proxies.
When it happens
Trigger: Previewing a script whose code fails server-side validation (400), hitting an endpoint that requires auth while the token is expired (401/403), the path/endpoint not existing on the target instance (404), or a reverse proxy returning 502/503.
Common situations: Expired or mis-scoped API token; pointing the CLI at the wrong instance URL (`--base-url`/workspace config) behind a proxy; previewing code with syntax errors the server rejects; corporate SSO/gateway challenging the request.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- Couldn't fetch resource types from hub ${hubBaseUrl}: ${(awa
- Couldn't fetch resource types from public hub:
- GET assets/graph -> ${res.status}: ${await res.text()}
- GET ${path} -> ${response.status}: ${body}
- Got an HTML response from ${url} (status ${status}${cfPart ?
AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03).
Data as JSON: /api/errors/efb1aabfd01734ff.
Report an issue: GitHub.