Mã
Node 22, không cần cài gói. Tạo khoá API trong n8n ở mục Settings, API, rồi chạy script với id của execution và tên node.
js
// Read one node's runs and errors from an n8n execution that is "too large to display".
// Usage: N8N_URL=YOUR_N8N_URL N8N_API_KEY=YOUR_API_KEY node read-node-error.mjs <executionId> ["Node name"]
import { createWriteStream } from "node:fs";
import { readFile } from "node:fs/promises";
import { Readable } from "node:stream";
import { pipeline } from "node:stream/promises";
const [id, nodeName] = process.argv.slice(2);
const base = (process.env.N8N_URL || "").replace(/\/+$/, "");
if (!id || !base || !process.env.N8N_API_KEY) throw new Error("Set N8N_URL, N8N_API_KEY and pass an execution id");
const url = `${base}/api/v1/executions/${encodeURIComponent(id)}?includeData=true&ignoreDataSizeLimit=true`;
const res = await fetch(url, { headers: { "X-N8N-API-KEY": process.env.N8N_API_KEY } });
if (!res.ok) {
const hint = res.status >= 502 ? " The proxy gave up on the full download; ask n8n support for this execution." : "";
throw new Error(`n8n API returned HTTP ${res.status}.${hint}`);
}
const file = `execution-${id}.json`; // keep a copy so you only download once
await pipeline(Readable.fromWeb(res.body), createWriteStream(file));
const exec = JSON.parse(await readFile(file, "utf8"));
if (exec.dataTooLargeToDisplay) throw new Error("Still too large: this n8n version ignores ignoreDataSizeLimit. Update n8n, or raise EXECUTIONS_DATA_MAX_DISPLAY_SIZE if you self-host.");
const runData = exec.data?.resultData?.runData ?? {};
const errorsOf = (run) => [
...(run.error ? [run.error] : []),
...(run.data?.main ?? []).flat().filter((item) => item?.json?.error).map((item) => item.json.error),
];
if (exec.data?.resultData?.error) console.log("Execution error:", exec.data.resultData.error.message);
if (!nodeName || !runData[nodeName]) {
if (nodeName) console.log(`No node named "${nodeName}" in this execution.`);
const failed = Object.entries(runData).filter(([, runs]) => runs.some((r) => errorsOf(r).length));
console.log("Nodes with errors:", failed.length ? failed.map(([name]) => name).join(", ") : "none");
process.exit(nodeName ? 1 : 0);
}
runData[nodeName].forEach((run, i) => {
const when = new Date(run.startTime).toISOString();
console.log(`Run ${i + 1}: ${when}, ${run.executionTime} ms, status ${run.executionStatus ?? "unknown"}`);
for (const err of errorsOf(run)) {
const msg = typeof err === "string" ? err : err.message;
console.log(" error:", msg, err.description ? `| ${err.description}` : "", err.httpCode ? `| HTTP ${err.httpCode}` : "");
}
});Vì sao xảy ra
n8n có giới hạn kích thước khi hiển thị dữ liệu execution, đặt bằng EXECUTIONS_DATA_MAX_DISPLAY_SIZE (mặc định 100 MB). Vượt quá mức này, n8n không nạp dữ liệu chạy nữa. Trình chỉnh sửa báo "too large to display", còn API trả data rỗng kèm dataTooLargeToDisplay: true.
Dữ liệu vẫn được lưu. Các bản API công khai gần đây nhận tham số ignoreDataSizeLimit=true để bỏ qua giới hạn đó cho một lần gọi. Script dùng tham số này, ghi phản hồi ra đĩa và chỉ in phần bạn cần.
Các bước
- Đặt
N8N_URLlà địa chỉ instance của bạn vàN8N_API_KEYlà khoá. Giữ khoá trong biến môi trường, không ghi vào tệp. - Chạy lần đầu chỉ với id execution. Script liệt kê mọi node có lỗi.
- Chạy lại kèm tên node. Script in từng lượt chạy: thời điểm bắt đầu theo UTC, thời gian chạy tính bằng mili giây, trạng thái và mọi lỗi.
- Lỗi nằm ở hai chỗ.
run.errorcó giá trị khi node làm dừng workflow. Khi node đặt "Continue (using error output)", lỗi nằm trong item ở nhánh lỗi, và script đọc cả chỗ này. - Tệp
execution-<id>.jsonđã tải vẫn nằm trong thư mục, nên bạn có thể tìm lại mà không phải gọi lại yêu cầu lớn.
Lưu ý
- Ở bản n8n cũ, tham số này bị bỏ qua và bạn nhận lại đúng phản hồi rỗng như trước. Khi đó script dừng và báo rõ. Nếu tự host, bạn có thể tăng
EXECUTIONS_DATA_MAX_DISPLAY_SIZE. - Tải tệp lớn có thể bị proxy cắt giữa chừng và trả về HTTP 502. Nếu gặp trên n8n Cloud, hãy gửi id execution và tên node cho bộ phận hỗ trợ của n8n.
- Lỗi đã lưu có thể chỉ là thông báo ngắn của n8n. Ví dụ lỗi 403 thường hiện thành "Forbidden - perhaps check your credentials?". Hãy xem thêm
httpCodevàdescription. - Error Workflow chỉ chạy khi cả execution thất bại. Với "Continue (using error output)", lượt chạy kết thúc là thành công, nên hãy gửi một bản ghi lỗi nhỏ (node, item, thông báo, thời điểm) ngay từ nhánh lỗi trong lúc chạy.
Thấy trên: n8n Community ·
Dịch vụ liên quan: Workflow tự động n8n, Make, Zapier