Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
emitter.on('error', (pluginName: string, error: StartError) => {
// hard error
if (error instanceof Error) {
const stackUtils = new StackUtils({
cwd: process.cwd(),
internals: StackUtils.nodeInternals()
})
const stack = stackUtils.clean(error.stack!)
console.error(`${chalk.red(`${taskName}.${pluginName}`)}: ${error.message}`)
console.error(`\n${chalk.red(stack)}`)
// array of "soft" errors
} else if (Array.isArray(error)) {
error.forEach((message) => {
console.error(`${chalk.red(`${taskName}.${pluginName}`)}: ${message}`)
})
// "soft" error
} else if (typeof error === 'string') {
console.error(`${chalk.red(`${taskName}.${pluginName}`)}: ${error}`)
}
import { GraphQLError } from "graphql";
import StackUtils from "stack-utils";
import { CoralError, CoralErrorContext } from "coral-server/errors";
import VError from "verror";
interface SerializedError {
id?: string;
message: string;
name: string;
stack?: string;
context?: CoralErrorContext | Record;
originalError?: SerializedError;
}
const stackUtils = new StackUtils();
const errSerializer = (err: Error) => {
const obj: SerializedError = {
message: err.message,
name: err.name,
};
if (err.stack) {
// Copy over a cleaned stack.
obj.stack = stackUtils.clean(err.stack);
}
if (err instanceof GraphQLError && err.originalError) {
// If the error was caused by another error, integrate it.
obj.originalError = errSerializer(err.originalError);
} else if (err instanceof CoralError) {
function getSourceReference(stackTrace: string): messages.ISourceReference {
const stack = new StackUtils({
cwd: process.cwd(),
internals: StackUtils.nodeInternals(),
})
const trace = stack.clean(stackTrace)
const callSite = stack.parseLine(trace.split('\n')[1])
const { file: uri, line } = callSite
return new messages.SourceReference({
uri,
location: new messages.Location({
line,
}),
})
}