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}`)
}
console.error(`${chalk.red(`${taskName}.${pluginName}`)}: error`)
'use strict';
const StackUtils = require('stack-utils');
const cleanStack = require('clean-stack');
const debug = require('debug')('ava');
// Ignore unimportant stack trace lines
let ignoreStackLines = [];
const avaInternals = /\/ava\/(?:lib\/|lib\/worker\/)?[\w-]+\.js:\d+:\d+\)?$/;
const avaDependencies = /\/node_modules\/(?:append-transform|bluebird|empower-core|nyc|require-precompiled|(?:ava\/node_modules\/)?(?:babel-runtime|core-js))\//;
const stackFrameLine = /^.+( \(.+:\d+:\d+\)|:\d+:\d+)$/; // eslint-disable-line prefer-named-capture-group
if (!debug.enabled) {
ignoreStackLines = StackUtils.nodeInternals();
ignoreStackLines.push(avaInternals);
ignoreStackLines.push(avaDependencies);
}
const stackUtils = new StackUtils({internals: ignoreStackLines});
function extractFrames(stack) {
return stack
.split('\n')
.map(line => line.trim())
.filter(line => stackFrameLine.test(line))
.join('\n');
}
/*
* Given a string value of the format generated for the `stack` property of a
new RegExp(resc(require.resolve('import-jsx'))),
]
: [])
: +process.env.TAP_DEV_LONGSTACK !== 1 ? [
/at internal\/.*\.js:\d+:\d+/m,
new RegExp(resc(require.resolve('esm'))),
new RegExp(resc(require.resolve('nyc').replace(/(node_modules[\/\\]nyc).*$/, '$1'))),
new RegExp(resc(require.resolve('import-jsx'))),
]
: []
sourceMapSupport.install({environment:'node', hookRequire: true})
let nodeInternals = []
try {
nodeInternals = StackUtils.nodeInternals()
} catch (error) {
// Do nothing.
}
module.exports = new StackUtils({
internals: nodeInternals.concat(skip),
wrapCallSite: sourceMapSupport.wrapCallSite
})
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,
}),
})
}
const { ApolloServer } = require('apollo-server-express');
const { formatError, isInstance: isApolloErrorInstance } = require('apollo-errors');
const ensureError = require('ensure-error');
const serializeError = require('serialize-error');
const StackUtils = require('stack-utils');
const cuid = require('cuid');
const { omit } = require('@keystone-alpha/utils');
const { logger } = require('@keystone-alpha/logger');
const { startAuthedSession, endAuthedSession } = require('@keystone-alpha/session');
const { NestedError } = require('./graphqlErrors');
const graphqlLogger = logger('graphql');
const stackUtil = new StackUtils({ cwd: process.cwd(), internals: StackUtils.nodeInternals() });
const cleanError = maybeError => {
if (!maybeError.stack) {
return maybeError;
}
maybeError.stack = stackUtil.clean(maybeError.stack);
return maybeError;
};
const safeFormatError = error => {
const formattedError = formatError(error, true);
if (formattedError) {
return cleanError(formattedError);
}
return serializeError(cleanError(error));
};