directus / directus

The flexible backend for all your projects 🐰 Turn your DB into a headless CMS, admin panels, or apps with a custom UI, instant APIs, auth & more.
https://directus.io
Other
28.26k stars 3.94k forks source link

Error handling and logging issue in the "run script" operation within the flows editor #18831

Closed iddar closed 1 year ago

iddar commented 1 year ago

Describe the Bug

I would like to report a bug in the Directus.io flows editor. I have encountered an issue with error handling, logging, and execution in operations of type "run script". When a script fails, the flow breaks without proper error handling, no corresponding log entry is created in the system logs, and the subsequent blocks attached to the error block are not executed. Below are the details of the error:

Error code and stacktrace:

directus  | [02:36:10] GET /flows?fields[]=*&fields[]=operations.*&limit=-1 200 37ms
directus  | [02:36:10] GET /flows/e0ce6876-d277-49cb-a8e4-561d85966f78?fields[]=*&fields[]=operations.* 200 12ms
directus  | [02:36:17.520] ERROR: Error could not be cloned.
directus  |     err: {
directus  |       "type": "DOMException",
directus  |       "message": "Error could not be cloned.",
directus  |       "stack":
directus  |           DataCloneError: Error could not be cloned.
directus  |               at new DOMException (node:internal/per_context/domexception:53:5)
directus  |               at structuredClone (node:internal/structured_clone:23:17)
directus  |               at redact (file:///directus/node_modules/.pnpm/file+api/node_modules/@directus/api/dist/utils/redact.js:11:19)
directus  |               at FlowManager.executeFlow (file:///directus/node_modules/.pnpm/file+api/node_modules/@directus/api/dist/flows.js:281:31)
directus  |               at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
directus  |               at async handler (file:///directus/node_modules/.pnpm/file+api/node_modules/@directus/api/dist/flows.js:176:42)
directus  |               at async file:///directus/node_modules/.pnpm/file+api/node_modules/@directus/api/dist/controllers/flows.js:16:38
directus  |       "name": "DataCloneError",
directus  |       "code": 25,
directus  |       "INDEX_SIZE_ERR": 1,
directus  |       "DOMSTRING_SIZE_ERR": 2,
directus  |       "HIERARCHY_REQUEST_ERR": 3,
directus  |       "WRONG_DOCUMENT_ERR": 4,
directus  |       "INVALID_CHARACTER_ERR": 5,
directus  |       "NO_DATA_ALLOWED_ERR": 6,
directus  |       "NO_MODIFICATION_ALLOWED_ERR": 7,
directus  |       "NOT_FOUND_ERR": 8,
directus  |       "NOT_SUPPORTED_ERR": 9,
directus  |       "INUSE_ATTRIBUTE_ERR": 10,
directus  |       "INVALID_STATE_ERR": 11,
directus  |       "SYNTAX_ERR": 12,
directus  |       "INVALID_MODIFICATION_ERR": 13,
directus  |       "NAMESPACE_ERR": 14,
directus  |       "INVALID_ACCESS_ERR": 15,
directus  |       "VALIDATION_ERR": 16,
directus  |       "TYPE_MISMATCH_ERR": 17,
directus  |       "SECURITY_ERR": 18,
directus  |       "NETWORK_ERR": 19,
directus  |       "ABORT_ERR": 20,
directus  |       "URL_MISMATCH_ERR": 21,
directus  |       "QUOTA_EXCEEDED_ERR": 22,
directus  |       "TIMEOUT_ERR": 23,
directus  |       "INVALID_NODE_TYPE_ERR": 24,
directus  |       "DATA_CLONE_ERR": 25
directus  |     }

Expected behavior:

The flow should handle errors in the "run script" operation gracefully, providing a proper error message, and executing the subsequent blocks attached to the error block. Additionally, a corresponding log entry should be created in the system logs to track the failed operation.

Additional Information:

Response from the "run script" operation:

{
    "errors": [
        {
            "message": "ReferenceError could not be cloned.",
            "extensions": {
                "code": "INTERNAL_SERVER_ERROR"
            }
        }
    ]
}

Any assistance or updates regarding this issue would be greatly appreciated. If you require additional information or further testing, I am available to collaborate in resolving this bug.

To Reproduce

Steps to reproduce the issue:

  1. Create a flow in the Directus.io flows editor.
  2. Add a "run script" operation with the following code:

    module.exports = async function(data) {
    if(data.websites.length === 0) {
       throw new Error('No items found');
    }
    
    return {
        websites: data.websites.length
    };
    }
  3. Save and execute the flow.
  4. Observe that the flow breaks without proper error handling, displaying the aforementioned error.
  5. Check the system logs and notice that no log entry is created for the failed "run script" operation.
image

Directus Version

10.2.1

Hosting Strategy

Self-Hosted (Docker Image)

paescuj commented 1 year ago

Thanks for opening this issue! However this is a duplicate of an existing issue #18751, so I'll proceed to close this but if you think this is actually a different issue, then please do not hesitate to comment. The existing issue #18751 has been fixed by #18777 which will be available with the next release.