update: save both stdout and stderr for aliyunfc error handling
This commit is contained in:
parent
2c503df172
commit
d5a317ea34
@ -255,7 +255,8 @@ class NetScheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async alicloudFcRequest<R>(url: string, region: string): Promise<R> {
|
private async alicloudFcRequest<R>(url: string, region: string): Promise<R> {
|
||||||
let rawOuput: null | Uint8Array = null;
|
let rawOutput: null | Uint8Array = null;
|
||||||
|
let rawErr: null | Uint8Array = null;
|
||||||
try {
|
try {
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
const output = await new Deno.Command("aliyun", {
|
const output = await new Deno.Command("aliyun", {
|
||||||
@ -273,14 +274,15 @@ class NetScheduler {
|
|||||||
`CVSA-${region}`,
|
`CVSA-${region}`,
|
||||||
],
|
],
|
||||||
}).output();
|
}).output();
|
||||||
rawOuput = output.stdout;
|
rawOutput = output.stdout;
|
||||||
|
rawErr = output.stderr;
|
||||||
const out = decoder.decode(output.stdout);
|
const out = decoder.decode(output.stdout);
|
||||||
const rawData = JSON.parse(out);
|
const rawData = JSON.parse(out);
|
||||||
if (rawData.statusCode !== 200) {
|
if (rawData.statusCode !== 200) {
|
||||||
const fileId = randomUUID();
|
const fileId = randomUUID();
|
||||||
const filePath = `./logs/files/${fileId}`;
|
await Deno.writeFile(`./logs/files/${fileId}.stdout`, output.stdout);
|
||||||
await Deno.writeFile(filePath, rawOuput);
|
await Deno.writeFile(`./logs/files/${fileId}.stderr`, output.stderr);
|
||||||
logger.log(`Returned non-200 status code. Raw ouput saved to ${filePath}.`, "net", "fn:alicloudFcRequest")
|
logger.log(`Returned non-200 status code. Raw ouput saved to ./logs/files/${fileId}.stdout/stderr`, "net", "fn:alicloudFcRequest")
|
||||||
throw new NetSchedulerError(
|
throw new NetSchedulerError(
|
||||||
`Error proxying ${url} to ali-fc region ${region}, code: ${rawData.statusCode}.`,
|
`Error proxying ${url} to ali-fc region ${region}, code: ${rawData.statusCode}.`,
|
||||||
"ALICLOUD_PROXY_ERR",
|
"ALICLOUD_PROXY_ERR",
|
||||||
@ -289,11 +291,11 @@ class NetScheduler {
|
|||||||
return JSON.parse(JSON.parse(rawData.body)) as R;
|
return JSON.parse(JSON.parse(rawData.body)) as R;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (rawOuput !== null) {
|
if (rawOutput !== null || rawErr !== null) {
|
||||||
const fileId = randomUUID();
|
const fileId = randomUUID();
|
||||||
const filePath = `./logs/files/${fileId}`;
|
rawOutput && await Deno.writeFile(`./logs/files/${fileId}.stdout`, rawOutput);
|
||||||
await Deno.writeFile(filePath, rawOuput);
|
rawErr && await Deno.writeFile(`./logs/files/${fileId}.stderr`, rawErr);
|
||||||
logger.log(`Error occurred. Raw ouput saved to ${filePath}.`, "net", "fn:alicloudFcRequest")
|
logger.log(`Error occurred. Raw ouput saved to ./logs/files/${fileId}.stdout/stderr`, "net", "fn:alicloudFcRequest")
|
||||||
}
|
}
|
||||||
logger.error(e as Error, "net", "fn:alicloudFcRequest");
|
logger.error(e as Error, "net", "fn:alicloudFcRequest");
|
||||||
throw new NetSchedulerError(`Unhandled error: Cannot proxy ${url} to ali-fc.`, "ALICLOUD_PROXY_ERR", e);
|
throw new NetSchedulerError(`Unhandled error: Cannot proxy ${url} to ali-fc.`, "ALICLOUD_PROXY_ERR", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user