enhance(logging): エラー時もっと詳しい情報が残るように (MisskeyIO#360)
This commit is contained in:
parent
bad14005f8
commit
411a8bd8e7
|
@ -71,7 +71,7 @@ if (!envOption.quiet) {
|
||||||
// Display detail of uncaught exception
|
// Display detail of uncaught exception
|
||||||
process.on('uncaughtException', err => {
|
process.on('uncaughtException', err => {
|
||||||
try {
|
try {
|
||||||
logger.error('Uncaught exception', { error: err });
|
logger.error(`Uncaught exception: ${err.message}`, { error: err });
|
||||||
} catch { }
|
} catch { }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import cluster from 'node:cluster';
|
import cluster from 'node:cluster';
|
||||||
|
import util from 'node:util';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { default as convertColor } from 'color-convert';
|
import { default as convertColor } from 'color-convert';
|
||||||
import { format as dateFormat } from 'date-fns';
|
import { format as dateFormat } from 'date-fns';
|
||||||
|
@ -11,6 +12,34 @@ import { bindThis } from '@/decorators.js';
|
||||||
import { envOption } from './env.js';
|
import { envOption } from './env.js';
|
||||||
import type { KEYWORD } from 'color-convert/conversions.js';
|
import type { KEYWORD } from 'color-convert/conversions.js';
|
||||||
|
|
||||||
|
util.inspect.defaultOptions = envOption.logJson ? {
|
||||||
|
showHidden: false,
|
||||||
|
depth: null,
|
||||||
|
colors: false,
|
||||||
|
customInspect: true,
|
||||||
|
showProxy: false,
|
||||||
|
maxArrayLength: null,
|
||||||
|
maxStringLength: null,
|
||||||
|
breakLength: Infinity,
|
||||||
|
compact: true,
|
||||||
|
sorted: false,
|
||||||
|
getters: false,
|
||||||
|
numericSeparator: false,
|
||||||
|
} : {
|
||||||
|
showHidden: false,
|
||||||
|
depth: null,
|
||||||
|
colors: true,
|
||||||
|
customInspect: true,
|
||||||
|
showProxy: false,
|
||||||
|
maxArrayLength: null,
|
||||||
|
maxStringLength: null,
|
||||||
|
breakLength: Infinity,
|
||||||
|
compact: true,
|
||||||
|
sorted: false,
|
||||||
|
getters: false,
|
||||||
|
numericSeparator: false,
|
||||||
|
};
|
||||||
|
|
||||||
type Context = {
|
type Context = {
|
||||||
name: string;
|
name: string;
|
||||||
color?: KEYWORD;
|
color?: KEYWORD;
|
||||||
|
@ -18,6 +47,13 @@ type Context = {
|
||||||
|
|
||||||
type Level = 'error' | 'success' | 'warning' | 'debug' | 'info';
|
type Level = 'error' | 'success' | 'warning' | 'debug' | 'info';
|
||||||
|
|
||||||
|
function inspect(_: string, value: any): null | string | number | boolean {
|
||||||
|
if (value === null || value === undefined) return null;
|
||||||
|
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return value;
|
||||||
|
if (value instanceof Date) return value.toISOString();
|
||||||
|
return util.inspect(value);
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-default-export
|
// eslint-disable-next-line import/no-default-export
|
||||||
export default class Logger {
|
export default class Logger {
|
||||||
private context: Context;
|
private context: Context;
|
||||||
|
@ -59,7 +95,7 @@ export default class Logger {
|
||||||
important: important,
|
important: important,
|
||||||
context: [this.context].concat(subContexts).map(d => d.name).join('.'),
|
context: [this.context].concat(subContexts).map(d => d.name).join('.'),
|
||||||
cluster: cluster.isPrimary ? 'primary' : `worker-${cluster.worker!.id}`,
|
cluster: cluster.isPrimary ? 'primary' : `worker-${cluster.worker!.id}`,
|
||||||
}));
|
}, inspect));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +122,7 @@ export default class Logger {
|
||||||
|
|
||||||
const args: unknown[] = [important ? chalk.bold(log) : log];
|
const args: unknown[] = [important ? chalk.bold(log) : log];
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
args.push(data);
|
args.push(JSON.stringify(data, inspect, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level === 'error' || level === 'warning') {
|
if (level === 'error' || level === 'warning') {
|
||||||
|
|
|
@ -77,8 +77,20 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
// Create file
|
// Create file
|
||||||
driveFile = await this.driveService.uploadFromUrl({ url: emoji.originalUrl, user: null, force: true });
|
driveFile = await this.driveService.uploadFromUrl({ url: emoji.originalUrl, user: null, force: true });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// TODO: need to return Drive Error
|
const err = e as Error;
|
||||||
throw new ApiError();
|
throw new ApiError(
|
||||||
|
{
|
||||||
|
message: 'Failed to upload image from URL.',
|
||||||
|
code: 'FAILED_TO_UPLOAD_IMAGE_FROM_URL',
|
||||||
|
id: '5c77c4d7-0f68-48f9-8694-8453a2294840',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
e: {
|
||||||
|
message: err.message,
|
||||||
|
code: err.name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Duplication Check
|
// Duplication Check
|
||||||
|
|
|
@ -113,13 +113,26 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
requestHeaders: instance.enableIpLogging ? headers : null,
|
requestHeaders: instance.enableIpLogging ? headers : null,
|
||||||
});
|
});
|
||||||
return await this.driveFileEntityService.pack(driveFile, me, { self: true });
|
return await this.driveFileEntityService.pack(driveFile, me, { self: true });
|
||||||
} catch (err) {
|
} catch (e) {
|
||||||
this.logger.error('Failed to create drive file', { error: err });
|
this.logger.error('Failed to create drive file', { error: e });
|
||||||
if (err instanceof IdentifiableError) {
|
if (e instanceof IdentifiableError) {
|
||||||
if (err.id === '282f77bf-5816-4f72-9264-aa14d8261a21') throw new ApiError(meta.errors.inappropriate);
|
if (e.id === '282f77bf-5816-4f72-9264-aa14d8261a21') throw new ApiError(meta.errors.inappropriate);
|
||||||
if (err.id === 'c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6') throw new ApiError(meta.errors.noFreeSpace);
|
if (e.id === 'c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6') throw new ApiError(meta.errors.noFreeSpace);
|
||||||
}
|
}
|
||||||
throw new ApiError();
|
const err = e as Error;
|
||||||
|
throw new ApiError(
|
||||||
|
{
|
||||||
|
message: 'Failed to create drive file.',
|
||||||
|
code: 'FAILED_TO_CREATE_DRIVE_FILE',
|
||||||
|
id: '6708863c-6791-4487-aa01-2d682c6e7db0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
e: {
|
||||||
|
message: err.message,
|
||||||
|
code: err.name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
cleanup!();
|
cleanup!();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue