Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'stack-utils' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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
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}`)
}
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
})
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) {
'use strict';
const StackUtils = require('stack-utils');
const original = StackUtils.prototype.parseLine;
let restored = false;
let restoreAfterFirstCall = false;
StackUtils.prototype.parseLine = function (line) {
if (restored) {
return original.call(this, line);
}
if (restoreAfterFirstCall) {
restored = true;
}
throw new Error('Forced error');
};
exports.restoreAfterFirstCall = () => {
restoreAfterFirstCall = true;
'use strict';
const StackUtils = require('stack-utils');
const original = StackUtils.prototype.parseLine;
let restored = false;
let restoreAfterFirstCall = false;
StackUtils.prototype.parseLine = function (line) {
if (restored) {
return original.call(this, line);
}
if (restoreAfterFirstCall) {
restored = true;
}
throw new Error('Forced error');
};
exports.restoreAfterFirstCall = () => {
restoreAfterFirstCall = true;
};
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,
}),
})
}
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));
};