refactor(core): Include native Python option in Code node (#18331)

This commit is contained in:
Iván Ovejero
2025-08-18 12:25:47 +02:00
committed by GitHub
parent adaa1180eb
commit 47cb4a07ca
6 changed files with 146 additions and 48 deletions

View File

@@ -1,13 +1,12 @@
import {
ApplicationError,
type CodeExecutionMode,
type IExecuteFunctions,
type INodeExecutionData,
type WorkflowExecuteMode,
} from 'n8n-workflow';
import { isWrappableError, WrappedExecutionError } from './errors/WrappedExecutionError';
import { validateNoDisallowedMethodsInRunForEach } from './JsCodeValidator';
import { throwExecutionError } from './throw-execution-error';
/**
* JS Code execution sandbox that executes the JS code using task runner.
@@ -37,7 +36,7 @@ export class JsTaskRunnerSandbox {
return executionResult.ok
? executionResult.result
: this.throwExecutionError('error' in executionResult ? executionResult.error : {});
: throwExecutionError('error' in executionResult ? executionResult.error : {});
}
async runCodeForEachItem(numInputItems: number): Promise<INodeExecutionData[]> {
@@ -64,7 +63,7 @@ export class JsTaskRunnerSandbox {
);
if (!executionResult.ok) {
return this.throwExecutionError('error' in executionResult ? executionResult.error : {});
return throwExecutionError('error' in executionResult ? executionResult.error : {});
}
executionResults = executionResults.concat(executionResult.result);
@@ -73,18 +72,6 @@ export class JsTaskRunnerSandbox {
return executionResults;
}
private throwExecutionError(error: unknown): never {
if (error instanceof Error) {
throw error;
} else if (isWrappableError(error)) {
// The error coming from task runner is not an instance of error,
// so we need to wrap it in an error instance.
throw new WrappedExecutionError(error);
}
throw new ApplicationError(`Unknown error: ${JSON.stringify(error)}`);
}
/** Chunks the input items into chunks of 1000 items each */
private chunkInputItems(numInputItems: number) {
const numChunks = Math.ceil(numInputItems / this.chunkSize);