Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (token.value === undefined) {
throw new InvalidInputError('JSON payload must not be undefined.');
} else if (token.value === null) {
value = token.value;
// @todo Deep check Array.
// eslint-disable-next-line no-negated-condition
} else if (!isPlainObject(token.value) && !Array.isArray(token.value)) {
throw new InvalidInputError('JSON payload must be a primitive value or a plain object.');
} else {
try {
value = JSON.stringify(token.value);
} catch (error) {
log.error({
error: serializeError(error),
}, 'payload cannot be stringified');
throw new InvalidInputError('JSON payload cannot be stringified.');
}
if (value === undefined) {
throw new InvalidInputError('JSON payload cannot be stringified. The resulting value is undefined.');
}
}
// Do not add `::json` as it will fail if an attempt is made to insert to jsonb-type column.
return {
sql: '$' + (greatestParameterPosition + 1),
values: [
value,
],
function addBreakCrumb(category: string, message: string, data: Object = {}, extraData) {
const hashedData = {};
Object.keys(data).forEach(key => (hashedData[key] = Analytics.hashData(data[key])));
const messageWithHashedData = format(message, hashedData);
extraData = extraData instanceof Error ? serializeError(extraData) : extraData;
Analytics.addBreadCrumb(category, messageWithHashedData, extraData);
}
}
let connection: InternalDatabaseConnectionType;
let remainingConnectionRetryLimit = clientConfiguration.connectionRetryLimit;
while (true) {
remainingConnectionRetryLimit--;
try {
connection = await pool.connect();
break;
} catch (error) {
parentLog.error({
error: serializeError(error),
remainingConnectionRetryLimit,
}, 'cannot establish connection');
if (remainingConnectionRetryLimit > 1) {
parentLog.info('retrying connection');
continue;
} else {
throw new ConnectionError(error.message);
}
}
}
if (!connection) {
throw new UnexpectedStateError('Connection handle is not present.');
}
const listener = async (event, data) => {
const browserWindow = BrowserWindow.fromWebContents(event.sender);
const send = (channel, data) => {
if (!(browserWindow && browserWindow.isDestroyed())) {
event.sender.send(channel, data);
}
};
const {dataChannel, errorChannel, userData} = data;
try {
send(dataChannel, await callback(userData, browserWindow));
} catch (error) {
send(errorChannel, serializeError(error));
}
};
function addBreadCrumb(category: string, message: string, data: Record = {}, extraData) {
const hashedData = {};
Object.keys(data).forEach(key => (hashedData[key] = Analytics.hashData(data[key])));
const messageWithHashedData = format(message, hashedData);
extraData = extraData instanceof Error ? serializeError(extraData) : extraData;
Analytics.addBreadCrumb(category, messageWithHashedData, extraData);
}
const serializedApplicationErrors = this.state.applicationErrors.map( ( error ) => serializeError( error ) );
const stackTrace = JSON.stringify( serializedApplicationErrors, null, 4 );
request.on('error', (error) => {
log.error({
error: serializeError(error),
}, 'request error');
});
error => event.sender.send(channel, id, 'error', serializeError(error)),
() => event.sender.send(channel, id, 'complete'),