mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
🐛 Swallow telemetry error and only log in warn and debug mode (#2858)
* catch nodegraph errors * use loglevel config for telemetry * Use getByNameAndVersion instead of getByName * remove any usage of nodeTypes.getByName method * deprecate getByName method
This commit is contained in:
@@ -1193,7 +1193,6 @@ export interface INodeTypes {
|
||||
nodeTypes: INodeTypeData;
|
||||
init(nodeTypes?: INodeTypeData): Promise<void>;
|
||||
getAll(): Array<INodeType | INodeVersionedType>;
|
||||
getByName(nodeType: string): INodeType | INodeVersionedType | undefined;
|
||||
getByNameAndVersion(nodeType: string, version?: number): INodeType | undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,10 @@ import {
|
||||
INodesGraphResult,
|
||||
IWorkflowBase,
|
||||
INodeTypes,
|
||||
INodeType,
|
||||
} from '.';
|
||||
|
||||
import { getInstance as getLoggerInstance } from './LoggerProxy';
|
||||
|
||||
export function getNodeTypeForName(workflow: IWorkflowBase, nodeName: string): INode | undefined {
|
||||
return workflow.nodes.find((node) => node.name === nodeName);
|
||||
}
|
||||
@@ -26,51 +27,59 @@ export function generateNodesGraph(
|
||||
};
|
||||
const nodeNameAndIndex: INodeNameIndex = {};
|
||||
|
||||
workflow.nodes.forEach((node: INode, index: number) => {
|
||||
nodesGraph.node_types.push(node.type);
|
||||
const nodeItem: INodeGraphItem = {
|
||||
type: node.type,
|
||||
position: node.position,
|
||||
try {
|
||||
workflow.nodes.forEach((node: INode, index: number) => {
|
||||
nodesGraph.node_types.push(node.type);
|
||||
const nodeItem: INodeGraphItem = {
|
||||
type: node.type,
|
||||
position: node.position,
|
||||
};
|
||||
|
||||
if (node.type === 'n8n-nodes-base.httpRequest') {
|
||||
try {
|
||||
nodeItem.domain = new URL(node.parameters.url as string).hostname;
|
||||
} catch (e) {
|
||||
nodeItem.domain = node.parameters.url as string;
|
||||
}
|
||||
} else {
|
||||
const nodeType = nodeTypes.getByNameAndVersion(node.type);
|
||||
|
||||
nodeType?.description.properties.forEach((property) => {
|
||||
if (
|
||||
property.name === 'operation' ||
|
||||
property.name === 'resource' ||
|
||||
property.name === 'mode'
|
||||
) {
|
||||
nodeItem[property.name] = property.default ? property.default.toString() : undefined;
|
||||
}
|
||||
});
|
||||
|
||||
nodeItem.operation = node.parameters.operation?.toString() ?? nodeItem.operation;
|
||||
nodeItem.resource = node.parameters.resource?.toString() ?? nodeItem.resource;
|
||||
nodeItem.mode = node.parameters.mode?.toString() ?? nodeItem.mode;
|
||||
}
|
||||
nodesGraph.nodes[`${index}`] = nodeItem;
|
||||
nodeNameAndIndex[node.name] = index.toString();
|
||||
});
|
||||
|
||||
const getGraphConnectionItem = (startNode: string, connectionItem: IConnection) => {
|
||||
return { start: nodeNameAndIndex[startNode], end: nodeNameAndIndex[connectionItem.node] };
|
||||
};
|
||||
|
||||
if (node.type === 'n8n-nodes-base.httpRequest') {
|
||||
try {
|
||||
nodeItem.domain = new URL(node.parameters.url as string).hostname;
|
||||
} catch (e) {
|
||||
nodeItem.domain = node.parameters.url as string;
|
||||
}
|
||||
} else {
|
||||
const nodeType = nodeTypes.getByName(node.type) as INodeType;
|
||||
nodeType.description.properties.forEach((property) => {
|
||||
if (
|
||||
property.name === 'operation' ||
|
||||
property.name === 'resource' ||
|
||||
property.name === 'mode'
|
||||
) {
|
||||
nodeItem[property.name] = property.default ? property.default.toString() : undefined;
|
||||
}
|
||||
});
|
||||
|
||||
nodeItem.operation = node.parameters.operation?.toString() ?? nodeItem.operation;
|
||||
nodeItem.resource = node.parameters.resource?.toString() ?? nodeItem.resource;
|
||||
nodeItem.mode = node.parameters.mode?.toString() ?? nodeItem.mode;
|
||||
}
|
||||
nodesGraph.nodes[`${index}`] = nodeItem;
|
||||
nodeNameAndIndex[node.name] = index.toString();
|
||||
});
|
||||
|
||||
const getGraphConnectionItem = (startNode: string, connectionItem: IConnection) => {
|
||||
return { start: nodeNameAndIndex[startNode], end: nodeNameAndIndex[connectionItem.node] };
|
||||
};
|
||||
|
||||
Object.keys(workflow.connections).forEach((nodeName) => {
|
||||
const connections = workflow.connections[nodeName];
|
||||
connections.main.forEach((element) => {
|
||||
element.forEach((element2) => {
|
||||
nodesGraph.node_connections.push(getGraphConnectionItem(nodeName, element2));
|
||||
Object.keys(workflow.connections).forEach((nodeName) => {
|
||||
const connections = workflow.connections[nodeName];
|
||||
connections.main.forEach((element) => {
|
||||
element.forEach((element2) => {
|
||||
nodesGraph.node_connections.push(getGraphConnectionItem(nodeName, element2));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
const logger = getLoggerInstance();
|
||||
logger.warn(`Failed to generate nodes graph for workflowId: ${workflow.id as string | number}`);
|
||||
logger.warn((e as Error).message);
|
||||
logger.warn((e as Error).stack ?? '');
|
||||
}
|
||||
|
||||
return { nodeGraph: nodesGraph, nameIndices: nodeNameAndIndex };
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
INodeType,
|
||||
INodeTypeData,
|
||||
INodeTypes,
|
||||
INodeVersionedType,
|
||||
IRunExecutionData,
|
||||
ITaskDataConnections,
|
||||
IWorkflowBase,
|
||||
@@ -614,7 +615,7 @@ class NodeTypesClass implements INodeTypes {
|
||||
return Object.values(this.nodeTypes).map((data) => NodeHelpers.getVersionedNodeType(data.type));
|
||||
}
|
||||
|
||||
getByName(nodeType: string): INodeType {
|
||||
getByName(nodeType: string): INodeType | INodeVersionedType | undefined {
|
||||
return this.getByNameAndVersion(nodeType);
|
||||
}
|
||||
|
||||
|
||||
@@ -618,7 +618,7 @@ describe('RoutingNode', () => {
|
||||
const runExecutionData: IRunExecutionData = { resultData: { runData: {} } };
|
||||
const additionalData = Helpers.WorkflowExecuteAdditionalData();
|
||||
const path = '';
|
||||
const nodeType = nodeTypes.getByName(node.type);
|
||||
const nodeType = nodeTypes.getByNameAndVersion(node.type);
|
||||
|
||||
const workflowData = {
|
||||
nodes: [node],
|
||||
@@ -1596,7 +1596,7 @@ describe('RoutingNode', () => {
|
||||
const connectionInputData: INodeExecutionData[] = [];
|
||||
const runExecutionData: IRunExecutionData = { resultData: { runData: {} } };
|
||||
const additionalData = Helpers.WorkflowExecuteAdditionalData();
|
||||
const nodeType = nodeTypes.getByName(baseNode.type);
|
||||
const nodeType = nodeTypes.getByNameAndVersion(baseNode.type);
|
||||
|
||||
const inputData: ITaskDataConnections = {
|
||||
main: [
|
||||
|
||||
Reference in New Issue
Block a user