Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(core): Don't fail task runner task if logging fails #12401

Merged
merged 5 commits into from
Dec 31, 2024

Conversation

tomi
Copy link
Contributor

@tomi tomi commented Dec 30, 2024

Summary

To conform to old Code Node behaviour, make sure JS task execution doesn't fail if logging fails. The issue mainly comes when trying to console.log the context object (e.g. this), because most of the built-ins are not serializable.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/CAT-447/console-logging-the-context-object-throws

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@n8n-assistant n8n-assistant bot added the n8n team Authored by the n8n team label Dec 30, 2024
Copy link

codecov bot commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@tomi tomi requested a review from netroy December 30, 2024 13:32
netroy
netroy previously approved these changes Dec 30, 2024
Copy link
Contributor

⚠️ Some Cypress E2E specs are failing, please fix them before merging

Copy link

cypress bot commented Dec 30, 2024

n8n    Run #8512

Run Properties:  status check passed Passed #8512  •  git commit 7a951806eb: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 tomi 🗃️ e2e/*
Project n8n
Branch Review cat-447-console-logging-the-context-object-throws
Run status status check passed Passed #8512
Run duration 04m 47s
Commit git commit 7a951806eb: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 tomi 🗃️ e2e/*
Committer Tomi Turtiainen
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 3
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 484
View all changes introduced in this branch ↗︎

Copy link
Contributor

⚠️ Some Cypress E2E specs are failing, please fix them before merging

Comment on lines +472 to +484
const context: Context = {
[inspect.custom]: () => '[[ExecutionContext]]',
require: this.requireResolver,
module: {},
console: this.buildCustomConsole(taskId),
$getWorkflowStaticData: (type: 'global' | 'node') => workflow.getStaticData(type, node),
...this.getNativeVariables(),
...dataProxy,
...this.buildRpcCallObject(taskId),
...additionalProperties,
};

return context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const context: Context = {
[inspect.custom]: () => '[[ExecutionContext]]',
require: this.requireResolver,
module: {},
console: this.buildCustomConsole(taskId),
$getWorkflowStaticData: (type: 'global' | 'node') => workflow.getStaticData(type, node),
...this.getNativeVariables(),
...dataProxy,
...this.buildRpcCallObject(taskId),
...additionalProperties,
};
return context;
return {
[inspect.custom]: () => '[[ExecutionContext]]',
require: this.requireResolver,
module: {},
console: this.buildCustomConsole(taskId),
$getWorkflowStaticData: (type: 'global' | 'node') => workflow.getStaticData(type, node),
...this.getNativeVariables(),
...dataProxy,
...this.buildRpcCallObject(taskId),
...additionalProperties,
};

Comment on lines +456 to +463
this.send({
type: 'runner:rpc',
callId,
taskId,
name,
params,
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no catch block here? Shouldn't we error the task if RPC fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RPC calls are initiated by user code. Hence it's up to the user code to handle or ignore them. If the user code throws, we of course error the task.

Copy link
Contributor

✅ All Cypress E2E specs passed

@tomi tomi merged commit 0860fbe into master Dec 31, 2024
64 checks passed
@tomi tomi deleted the cat-447-console-logging-the-context-object-throws branch December 31, 2024 07:19
@github-actions github-actions bot mentioned this pull request Jan 8, 2025
@janober
Copy link
Member

janober commented Jan 9, 2025

Got released with n8n@1.74.1

1 similar comment
@janober
Copy link
Member

janober commented Jan 9, 2025

Got released with n8n@1.74.1

@janober
Copy link
Member

janober commented Jan 9, 2025

Got released with n8n@1.74.0

1 similar comment
@janober
Copy link
Member

janober commented Jan 9, 2025

Got released with n8n@1.74.0

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
n8n team Authored by the n8n team Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants