Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLSP-1195: Handle parsing errors in winston logger #82

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion examples/workflow-server/src/node/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import 'reflect-metadata';

import { configureELKLayoutModule } from '@eclipse-glsp/layout-elk';
import { createAppModule, GModelStorage, SocketServerLauncher, WebSocketServerLauncher } from '@eclipse-glsp/server/node';
import { createAppModule, GModelStorage, Logger, SocketServerLauncher, WebSocketServerLauncher } from '@eclipse-glsp/server/node';
import { Container } from 'inversify';

import { WorkflowLayoutConfigurator } from '../common/layout/workflow-layout-configurator';
Expand All @@ -27,6 +27,16 @@ async function launch(argv?: string[]): Promise<void> {
const options = createWorkflowCliParser().parse(argv);
const appContainer = new Container();
appContainer.load(createAppModule(options));
const logger = appContainer.get(Logger);

// Add fallback hooks to catch unhandled exceptions & promise rejections and prevent the node process from crashing
process.on('unhandledRejection', (reason, p) => {
logger.error('Unhandled Rejection:', p, reason);
});

process.on('uncaughtException', error => {
logger.error('Uncaught exception:', error);
});

const elkLayoutModule = configureELKLayoutModule({ algorithms: ['layered'], layoutConfigurator: WorkflowLayoutConfigurator });
const serverModule = new WorkflowServerModule().configureDiagramModule(new WorkflowDiagramModule(() => GModelStorage), elkLayoutModule);
Expand Down
6 changes: 5 additions & 1 deletion packages/server/src/node/di/winston-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export class WinstonLogger extends Logger {
return `${param.message}
${param.stack || ''}`;
}
return JSON.stringify(param, undefined, 4);
try {
return JSON.stringify(param, undefined, 4);
} catch (_) {
return '';
}
}
}
Loading