Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor(core): Migrate all errors in cli package to new hierarchy #13478

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

ivov
Copy link
Contributor

@ivov ivov commented Feb 24, 2025

Follow-up to: #12267

Exempting webhook-helpers.ts which is currently being refactored.

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Feb 24, 2025
@ivov ivov marked this pull request as ready for review February 25, 2025 10:31
@ivov ivov requested a review from a team as a code owner February 25, 2025 10:31
Copy link
Collaborator

@tomi tomi left a comment

Choose a reason for hiding this comment

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

Few comments about which error class to use. Didn't go through all of them as there are so many. In the future maybe we can do these in smaller batches so they are easier to review.

@@ -238,7 +238,7 @@ export class ActiveWorkflowManager {
});

if (workflowData === null) {
throw new ApplicationError('Could not find workflow', { extra: { workflowId } });
throw new UnexpectedError('Could not find workflow', { extra: { workflowId } });
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could change the .findOne above to .findOneOrFail and remove this if, as non BaseErrors are treated as unexpected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer not to change any logic in this PR if possible.


export class AbortedExecutionRetryError extends ApplicationError {
export class AbortedExecutionRetryError extends UnexpectedError {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this error transient by nature? If so it should extend OperationalError instead

Copy link
Contributor Author

@ivov ivov Feb 25, 2025

Choose a reason for hiding this comment

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

This error is part of a workaround for the root issue that we should not be sending requests to retry an execution that was cancelled before starting.


export class ExternalSecretsProviderNotFoundError extends ApplicationError {
export class ExternalSecretsProviderNotFoundError extends UnexpectedError {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The provider name seems to be coming in a request to the controller. Hence that makes this a UserError as it can fail due to input from user

Copy link
Contributor Author

@ivov ivov Feb 25, 2025

Choose a reason for hiding this comment

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

The frontend should never allow sending an external secrets provider name that does not exist.

@@ -146,7 +146,7 @@ export class ExecutionService {
if (!execution.data.executionData) throw new AbortedExecutionRetryError();

if (execution.finished) {
throw new ApplicationError('The execution succeeded, so it cannot be retried.');
throw new UnexpectedError('The execution succeeded, so it cannot be retried.');
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is transient? So OperationalError?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This error is part of a workaround for the root issue that we should not be sending requests to retry an execution with success status.

@@ -188,7 +188,7 @@ export class ExecutionService {
})) as IWorkflowBase;

if (workflowData === undefined) {
throw new ApplicationError(
throw new UnexpectedError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this happen if the execution or workflow gets deleted? Should it be OperationalError or UserError instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this and the above cases, we've been assuming that trying to operate on a resource that no longer exists is a UserError. I don't fully agree and would rather err on the side of caution, but I'll go with UserError to be consistent.

@@ -44,7 +44,7 @@ export const parseRangeQuery = (

if (jsonFilter.waitTill) jsonFilter.waitTill = Boolean(jsonFilter.waitTill);

if (!isValid(jsonFilter)) throw new ApplicationError('Query does not match schema');
if (!isValid(jsonFilter)) throw new UnexpectedError('Query does not match schema');
Copy link
Collaborator

Choose a reason for hiding this comment

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

This input is coming from users --> UserError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is coming from our own frontend. Cases like I'd think this is unexpected and we'd want to report it?


export class TaskDeferredError extends ApplicationError {
export class TaskDeferredError extends UserError {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is transient --> OperationalError

Copy link
Contributor Author

@ivov ivov Feb 25, 2025

Choose a reason for hiding this comment

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

This is a special case in that we're relying on this to give time to the launcher to start a runner. So not really an error at all, so not sure any of the existing categories fit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants