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,
],
//
// We wrap the server side state generation inside a try/catch to have the ability to fall back to an
// server AND client saga behavior if the state generation failed.
//
try {
const {store, rootSagaInstance} = createStoreContext({
reduxSagaContext: 'server'
});
await rootSagaInstance.done;
initialState = store.getState();
} catch (e) {
reduxSagaContext = 'universal';
errors.push(serialize(e));
}
return {
query,
reduxSagaContext,
errors,
initialState
};
}
return ( ...args )=>{
var action = null
try{
action = creator( ...args )
}
catch( e ){
action = {type: NEW_THROWN_ERR, error: true, payload: serializeError(e) }
}
finally{
return action // eslint-disable-line no-unsafe-finally
}
}
function deserializeResults(results): ?SpecsResultsWithMetaData {
if (!results) return undefined;
if (results.type === 'error') {
let deserializedError = deserializeError(results.error);
// Special desrialization for external errors
if (deserializedError.originalErrors) {
const deserializedOriginalErrors = deserializedError.originalErrors.map(deserializeError);
if (results.error.name === ExternalBuildErrors.name) {
deserializedError = new ExternalBuildErrors(deserializedError.id, deserializedOriginalErrors);
} else if (results.error.name === ExternalTestErrors.name) {
deserializedError = new ExternalTestErrors(deserializedError.id, deserializedOriginalErrors);
} else {
deserializedError = new ExternalErrors(deserializedOriginalErrors);
}
}
if (deserializedError.originalError) {
const deserializedOriginalError = deserializeError(deserializedError.originalError);
const compName =
deserializedError.compName && typeof deserializedError.compName === 'string' ? deserializedError.compName : '';
deserializedError = new ExternalTestErrors(compName, [deserializedOriginalError]);
function deserializeResults(results): SpecsResultsWithMetaData | null | undefined {
if (!results) return undefined;
if (results.type === 'error') {
let deserializedError = deserializeError(results.error);
// Special desrialization for external errors
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
if (deserializedError.originalErrors) {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
const deserializedOriginalErrors = deserializedError.originalErrors.map(deserializeError);
if (results.error.name === ExternalBuildErrors.name) {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
deserializedError = new ExternalBuildErrors(deserializedError.id, deserializedOriginalErrors);
} else if (results.error.name === ExternalTestErrors.name) {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
deserializedError = new ExternalTestErrors(deserializedError.id, deserializedOriginalErrors);
} else {
deserializedError = new ExternalErrors(deserializedOriginalErrors);
}
}
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
const deserializedOriginalErrors = deserializedError.originalErrors.map(deserializeError);
if (results.error.name === ExternalBuildErrors.name) {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
deserializedError = new ExternalBuildErrors(deserializedError.id, deserializedOriginalErrors);
} else if (results.error.name === ExternalTestErrors.name) {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
deserializedError = new ExternalTestErrors(deserializedError.id, deserializedOriginalErrors);
} else {
deserializedError = new ExternalErrors(deserializedOriginalErrors);
}
}
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
if (deserializedError.originalError) {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
const deserializedOriginalError = deserializeError(deserializedError.originalError);
const compName =
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
deserializedError.compName && typeof deserializedError.compName === 'string' ? deserializedError.compName : '';
deserializedError = new ExternalTestErrors(compName, [deserializedOriginalError]);
}
const finalResults = {
type: 'error',
error: deserializedError
};
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
return finalResults;
}
const deserializeFailure = failure => {
if (!failure) return undefined;
if (!results) return undefined;
if (results.type === 'error') {
let deserializedError = deserializeError(results.error);
// Special desrialization for external errors
if (deserializedError.originalErrors) {
const deserializedOriginalErrors = deserializedError.originalErrors.map(deserializeError);
if (results.error.name === ExternalBuildErrors.name) {
deserializedError = new ExternalBuildErrors(deserializedError.id, deserializedOriginalErrors);
} else if (results.error.name === ExternalTestErrors.name) {
deserializedError = new ExternalTestErrors(deserializedError.id, deserializedOriginalErrors);
} else {
deserializedError = new ExternalErrors(deserializedOriginalErrors);
}
}
if (deserializedError.originalError) {
const deserializedOriginalError = deserializeError(deserializedError.originalError);
const compName =
deserializedError.compName && typeof deserializedError.compName === 'string' ? deserializedError.compName : '';
deserializedError = new ExternalTestErrors(compName, [deserializedOriginalError]);
}
const finalResults = {
type: 'error',
error: deserializedError
};
return finalResults;
}
const deserializeFailure = (failure) => {
if (!failure) return undefined;
const deserializedFailure = failure;
if (failure.err) {
try {
deserializedFailure.err = deserializeError(failure.err);
.then(({ id, value, reason }) => {
if (this.debug) {
console.log(
'[webview-crypto] Received message:',
JSON.stringify({
id,
value,
reason,
}),
);
}
if (!id) {
console.warn(
'[webview-crypto] no ID passed back from message:',
JSON.stringify(serializeError(reason)),
);
return;
}
const { resolve, reject } = this.messages[id];
if (value) {
resolve(value);
} else {
reject(reason);
}
delete this.messages[id];
})
.catch((reason) => {
pubsub,
socket,
storage,
availableRoomTypes,
onRoomDisposed,
request.type,
await roomFetcher.getListOfRooms(),
request.options,
customRoomIdGenerator
)
Logger(`${room.roomId} made`, LoggerTypes.room)
onRoomMade(room)
socket.emit(`${request.uniqueRequestId}-create`, room.roomId)
} catch (e) {
const error = serializeError(e)
Logger(
`${socket.id} error creating room - ${JSON.stringify(error)}`,
LoggerTypes.room
)
socket.emit(`${request.uniqueRequestId}-error`, error)
}
}
)
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);
}