mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 13:27:31 -08:00
fix(AWS DynamoDB Node): Add missing type assertion (no-changelog) (#5003)
fix(AWS DynamoDB Node): add type assertion
This commit is contained in:
parent
87d8865ad3
commit
e4785da2e1
|
@ -1,4 +1,4 @@
|
|||
import { deepCopy, IDataObject, INodeExecutionData } from 'n8n-workflow';
|
||||
import { deepCopy, IDataObject, INodeExecutionData, assert } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
AdjustedPutItem,
|
||||
|
@ -82,7 +82,11 @@ function decodeAttribute(type: AttributeValueType, attribute: string | IAttribut
|
|||
case 'NS':
|
||||
return attribute;
|
||||
case 'M':
|
||||
return simplify(attribute as IAttributeValue);
|
||||
assert(
|
||||
typeof attribute === 'object' && !Array.isArray(attribute) && attribute !== null,
|
||||
'Attribute must be an object',
|
||||
);
|
||||
return simplify(attribute);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ export * from './WorkflowErrors';
|
|||
export * from './WorkflowHooks';
|
||||
export * from './VersionedNodeType';
|
||||
export { LoggerProxy, NodeHelpers, ObservableObject, TelemetryHelpers };
|
||||
export { deepCopy, jsonParse, sleep, fileTypeFromMimeType } from './utils';
|
||||
export { deepCopy, jsonParse, sleep, fileTypeFromMimeType, assert } from './utils';
|
||||
export {
|
||||
isINodeProperties,
|
||||
isINodePropertyOptions,
|
||||
|
|
|
@ -74,3 +74,21 @@ export function fileTypeFromMimeType(mimeType: string): BinaryFileType | undefin
|
|||
if (mimeType.startsWith('text/')) return 'text';
|
||||
return;
|
||||
}
|
||||
|
||||
export function assert<T>(condition: T, msg?: string): asserts condition {
|
||||
if (!condition) {
|
||||
const error = new Error(msg ?? 'Invalid assertion');
|
||||
// hide assert stack frame if supported
|
||||
if (Error.hasOwnProperty('captureStackTrace')) {
|
||||
// V8 only - https://nodejs.org/api/errors.html#errors_error_capturestacktrace_targetobject_constructoropt
|
||||
Error.captureStackTrace(error, assert);
|
||||
} else if (error.stack) {
|
||||
// fallback for IE and Firefox
|
||||
error.stack = error.stack
|
||||
.split('\n')
|
||||
.slice(1) // skip assert function from stack frames
|
||||
.join('\n');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue