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

Bug Report: Sort Node Fails with Sort by number in "Simple" mode, while in code mode sometimes randomly giving "Sort code doesn't return" Error for my code! #12391

Open
ARHAEEM opened this issue Dec 28, 2024 · 1 comment
Labels
in linear Issue or PR has been created in Linear for internal review

Comments

@ARHAEEM
Copy link

ARHAEEM commented Dec 28, 2024

Bug Description

The Sort node occasionally fails with the Simple and with the Code mode giving error:
"Sort code doesn't return. Please add a 'return' statement to your code."
This occurs despite having an explicit return statement in the custom sort code. The issue may be due to edge cases in the provided JavaScript code or internal node handling.

Screenshots

image
image

Workflow Example

Here is a minimal reproducible workflow:

{
  "nodes": [
    {
      "parameters": {
        "resource": "folder",
        "operation": "list",
        "path": "=/DBL/Accounts/{{ $('Start').item.json[\"Code\"] }}",
        "returnAll": true,
        "filters": {}
      },
      "type": "n8n-nodes-base.dropbox",
      "typeVersion": 1,
      "position": [
        -2280,
        0
      ],
      "id": "5443a130-84cd-4af3-84ee-c00e75d54e0e",
      "name": "Dropbox",
      "credentials": {
        "dropboxApi": {
          "id": "21XgoCaTFmXIQLhc",
          "name": "dbx-auto"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "91776c35-4e28-417a-9bc7-4abf984c067b",
              "leftValue": "={{ $json.name }}",
              "rightValue": "={{ $json.name.match(/^\\d+_/) ? $json.name.match(/^\\d+_/)[0] : null }}",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              }
            },
            {
              "id": "99e05d9e-574b-4d1e-808b-2e82077762af",
              "leftValue": "={{ $json.name.match(/^\\d+_/) }}",
              "rightValue": "null",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {
          "ignoreCase": true
        }
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        -2120,
        0
      ],
      "id": "887d3b5a-efa1-4724-b8c2-6e9e61e02bee",
      "name": "Filter"
    },
    {
      "parameters": {
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "name",
              "order": "descending"
            }
          ]
        },
        "options": {
          "disableDotNotation": true
        }
      },
      "type": "n8n-nodes-base.sort",
      "typeVersion": 1,
      "position": [
        -1940,
        0
      ],
      "id": "7186cb2e-2135-4446-ae87-961ea5b3307e",
      "name": "Sort"
    }
  ],
  "connections": {
    "Dropbox": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter": {
      "main": [
        [
          {
            "node": "Sort",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort": {
      "main": [
        []
      ]
    }
  },
  "pinData": {
    "Dropbox": [
      {
        "id": "id:wvTgQWqrar0AAAAAAAAvmw",
        "name": "rsjykbr6_MainScreen.png",
        "lastModifiedClient": "2024-12-27T00:00:03Z",
        "lastModifiedServer": "2024-12-27T00:00:04Z",
        "rev": "0162a3525156db2000000013151e9d1",
        "contentSize": 291446,
        "type": "file",
        "contentHash": "4ca435acd56c67c94935ced86145bf09c54a41b798a51005592bcd012859033a",
        "pathLower": "/dbl/accounts/rsjykbr6/rsjykbr6_mainscreen.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/rsjykbr6_MainScreen.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAAvnA",
        "name": "rsjykbr6_MedalExchange.png",
        "lastModifiedClient": "2024-12-27T00:00:04Z",
        "lastModifiedServer": "2024-12-27T00:00:04Z",
        "rev": "0162a35251b877d000000013151e9d1",
        "contentSize": 424343,
        "type": "file",
        "contentHash": "f8f2d9b8cd7a45f1a4a709000c1bbc6525c3496aae311591372951652f54dcb9",
        "pathLower": "/dbl/accounts/rsjykbr6/rsjykbr6_medalexchange.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/rsjykbr6_MedalExchange.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAAvnQ",
        "name": "rsjykbr6_ZenkaiAwk.png",
        "lastModifiedClient": "2024-12-27T00:00:04Z",
        "lastModifiedServer": "2024-12-27T00:00:04Z",
        "rev": "0162a35252182cb000000013151e9d1",
        "contentSize": 251716,
        "type": "file",
        "contentHash": "f06afe93f1b8398483b113148a6abe34e313268cecd9ae88fab424c952b0cb98",
        "pathLower": "/dbl/accounts/rsjykbr6/rsjykbr6_zenkaiawk.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/rsjykbr6_ZenkaiAwk.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAAvng",
        "name": "rsjykbr6_Sparking.png",
        "lastModifiedClient": "2024-12-27T00:00:05Z",
        "lastModifiedServer": "2024-12-27T00:00:05Z",
        "rev": "0162a352527f285000000013151e9d1",
        "contentSize": 2290641,
        "type": "file",
        "contentHash": "44975301a60a455473869b077bf778a944c600a8a77d26c6e219d84e89e2dd55",
        "pathLower": "/dbl/accounts/rsjykbr6/rsjykbr6_sparking.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/rsjykbr6_Sparking.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAAvnw",
        "name": "rsjykbr6_Extreme.png",
        "lastModifiedClient": "2024-12-27T00:00:05Z",
        "lastModifiedServer": "2024-12-27T00:00:05Z",
        "rev": "0162a35252d19fc000000013151e9d1",
        "contentSize": 1687963,
        "type": "file",
        "contentHash": "2dbc4758d3dbe0d21983662f6debaba942de630030b4896ff30b2997e898b118",
        "pathLower": "/dbl/accounts/rsjykbr6/rsjykbr6_extreme.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/rsjykbr6_Extreme.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAAvoA",
        "name": "rsjykbr6_all_combined.png",
        "lastModifiedClient": "2024-12-27T00:00:05Z",
        "lastModifiedServer": "2024-12-27T00:00:05Z",
        "rev": "0162a3525316499000000013151e9d1",
        "contentSize": 5869021,
        "type": "file",
        "contentHash": "f52bb9272a0ab8d489039ee507aa05cadf05ddedbf1d5a4c22f51f9ce3db44f0",
        "pathLower": "/dbl/accounts/rsjykbr6/rsjykbr6_all_combined.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/rsjykbr6_all_combined.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAAvoQ",
        "name": "rsjykbr6_ULTRA.png",
        "lastModifiedClient": "2024-12-27T00:00:06Z",
        "lastModifiedServer": "2024-12-27T00:00:06Z",
        "rev": "0162a352539cb7c000000013151e9d1",
        "contentSize": 242349,
        "type": "file",
        "contentHash": "46f038b9be1329c45c25c2846cb5030f821b28231185f5d49bd6169fa9b17cf2",
        "pathLower": "/dbl/accounts/rsjykbr6/rsjykbr6_ultra.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/rsjykbr6_ULTRA.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAAvpw",
        "name": "rsjykbr6_MultiZLL.png",
        "lastModifiedClient": "2024-12-27T00:00:09Z",
        "lastModifiedServer": "2024-12-27T00:00:10Z",
        "rev": "0162a352571be1d000000013151e9d1",
        "contentSize": 237680,
        "type": "file",
        "contentHash": "332db831531fa3068575771070bef1ed25020fccda035697581ae23a8abd7694",
        "pathLower": "/dbl/accounts/rsjykbr6/rsjykbr6_multizll.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/rsjykbr6_MultiZLL.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAAvqA",
        "name": "rsjykbr6_LFs.png",
        "lastModifiedClient": "2024-12-27T00:00:10Z",
        "lastModifiedServer": "2024-12-27T00:00:10Z",
        "rev": "0162a3525776683000000013151e9d1",
        "contentSize": 267474,
        "type": "file",
        "contentHash": "7115f4fa82f874cee2e802423faf422862201c61a53df48fc87763de20912ba8",
        "pathLower": "/dbl/accounts/rsjykbr6/rsjykbr6_lfs.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/rsjykbr6_LFs.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAAvqQ",
        "name": "rsjykbr6_Hero.png",
        "lastModifiedClient": "2024-12-27T00:00:10Z",
        "lastModifiedServer": "2024-12-27T00:00:10Z",
        "rev": "0162a35257cd976000000013151e9d1",
        "contentSize": 554121,
        "type": "file",
        "contentHash": "69d263894b6b0b163ae064d4488266d94e48e6947cef15c1cea2f12b47f7def7",
        "pathLower": "/dbl/accounts/rsjykbr6/rsjykbr6_hero.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/rsjykbr6_Hero.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAAwtw",
        "name": "Banner.png",
        "lastModifiedClient": "2024-12-27T01:02:36Z",
        "lastModifiedServer": "2024-12-27T01:02:36Z",
        "rev": "0162a3604beb39d000000013151e9d1",
        "contentSize": 1714293,
        "type": "file",
        "contentHash": "b377496a6f6e12ec2ab6bd2562bdf66d1a33616d20ee722303dde455797529ea",
        "pathLower": "/dbl/accounts/rsjykbr6/banner.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/Banner.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4vQ",
        "name": "2_rsjykbr6_Hero_1.png",
        "lastModifiedClient": "2024-12-27T20:06:38Z",
        "lastModifiedServer": "2024-12-27T20:06:39Z",
        "rev": "0162a46002ac32e000000013151e9d1",
        "contentSize": 297126,
        "type": "file",
        "contentHash": "50c755599a6b54748b98e74c1878bf0b6c670f232443c5eaa8c456a3c800a3e8",
        "pathLower": "/dbl/accounts/rsjykbr6/2_rsjykbr6_hero_1.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/2_rsjykbr6_Hero_1.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4vg",
        "name": "3_rsjykbr6_Hero_2.png",
        "lastModifiedClient": "2024-12-27T20:06:39Z",
        "lastModifiedServer": "2024-12-27T20:06:39Z",
        "rev": "0162a46002fe187000000013151e9d1",
        "contentSize": 297316,
        "type": "file",
        "contentHash": "9ebf6512612465c53871d9af703ad6724b173bc0189219fcb483e20dcc9f8921",
        "pathLower": "/dbl/accounts/rsjykbr6/3_rsjykbr6_hero_2.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/3_rsjykbr6_Hero_2.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4vw",
        "name": "4_rsjykbr6_Extreme_1.png",
        "lastModifiedClient": "2024-12-27T20:06:39Z",
        "lastModifiedServer": "2024-12-27T20:06:39Z",
        "rev": "0162a4600364d55000000013151e9d1",
        "contentSize": 307815,
        "type": "file",
        "contentHash": "9f5c021bee2ff2195f573a0cd941fb2b4c1b2ba40ec315e037eecaaf82fdf84b",
        "pathLower": "/dbl/accounts/rsjykbr6/4_rsjykbr6_extreme_1.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/4_rsjykbr6_Extreme_1.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4wA",
        "name": "9_rsjykbr6_Sparking_1.png",
        "lastModifiedClient": "2024-12-27T20:06:40Z",
        "lastModifiedServer": "2024-12-27T20:06:40Z",
        "rev": "0162a46003fd429000000013151e9d1",
        "contentSize": 322382,
        "type": "file",
        "contentHash": "72855f6b26309fc618ea61aab72bba64adf4071fa33372f0085317e33ead8a9c",
        "pathLower": "/dbl/accounts/rsjykbr6/9_rsjykbr6_sparking_1.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/9_rsjykbr6_Sparking_1.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4wQ",
        "name": "6_rsjykbr6_Extreme_3.png",
        "lastModifiedClient": "2024-12-27T20:06:40Z",
        "lastModifiedServer": "2024-12-27T20:06:40Z",
        "rev": "0162a4600446f6b000000013151e9d1",
        "contentSize": 308172,
        "type": "file",
        "contentHash": "faf3e52e8ef8390ae93edca8682eab3dcb5dd552c217d4bdf452a3d226ed0af2",
        "pathLower": "/dbl/accounts/rsjykbr6/6_rsjykbr6_extreme_3.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/6_rsjykbr6_Extreme_3.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4wg",
        "name": "14_rsjykbr6_Sparking_6.png",
        "lastModifiedClient": "2024-12-27T20:06:40Z",
        "lastModifiedServer": "2024-12-27T20:06:41Z",
        "rev": "0162a46004a1e82000000013151e9d1",
        "contentSize": 310488,
        "type": "file",
        "contentHash": "5e49c0d7ab49bd8eb72765e54fd866744fd45108961b1913535f471d133bfa06",
        "pathLower": "/dbl/accounts/rsjykbr6/14_rsjykbr6_sparking_6.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/14_rsjykbr6_Sparking_6.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4ww",
        "name": "13_rsjykbr6_Sparking_5.png",
        "lastModifiedClient": "2024-12-27T20:06:41Z",
        "lastModifiedServer": "2024-12-27T20:06:41Z",
        "rev": "0162a460050921a000000013151e9d1",
        "contentSize": 311148,
        "type": "file",
        "contentHash": "49c86b9976f47afbf55fbcf1fd88d48a31ab8d287073fd45aa9a2c74a5d6d48a",
        "pathLower": "/dbl/accounts/rsjykbr6/13_rsjykbr6_sparking_5.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/13_rsjykbr6_Sparking_5.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4xA",
        "name": "5_rsjykbr6_Extreme_2.png",
        "lastModifiedClient": "2024-12-27T20:06:45Z",
        "lastModifiedServer": "2024-12-27T20:06:45Z",
        "rev": "0162a46008b0f04000000013151e9d1",
        "contentSize": 309687,
        "type": "file",
        "contentHash": "1de7a4415f563400ac9f599b3e9977cb06108067261a7354f8a8668739ce87e0",
        "pathLower": "/dbl/accounts/rsjykbr6/5_rsjykbr6_extreme_2.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/5_rsjykbr6_Extreme_2.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4xQ",
        "name": "12_rsjykbr6_Sparking_4.png",
        "lastModifiedClient": "2024-12-27T20:06:45Z",
        "lastModifiedServer": "2024-12-27T20:06:45Z",
        "rev": "0162a4600907a3c000000013151e9d1",
        "contentSize": 322122,
        "type": "file",
        "contentHash": "cdc669677a429c1c85dbbda76c49c59e0370e17d894cf54824afb43a2a08c83f",
        "pathLower": "/dbl/accounts/rsjykbr6/12_rsjykbr6_sparking_4.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/12_rsjykbr6_Sparking_4.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4xg",
        "name": "10_rsjykbr6_Sparking_2.png",
        "lastModifiedClient": "2024-12-27T20:06:45Z",
        "lastModifiedServer": "2024-12-27T20:06:46Z",
        "rev": "0162a460096638e000000013151e9d1",
        "contentSize": 315392,
        "type": "file",
        "contentHash": "ac2ddc7a4f79301b0f7def1ba6baf5a2a93e17e672dee22daf2b44d9e8747b56",
        "pathLower": "/dbl/accounts/rsjykbr6/10_rsjykbr6_sparking_2.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/10_rsjykbr6_Sparking_2.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4xw",
        "name": "17_rsjykbr6_LFs_1.png",
        "lastModifiedClient": "2024-12-27T20:06:46Z",
        "lastModifiedServer": "2024-12-27T20:06:46Z",
        "rev": "0162a46009defe1000000013151e9d1",
        "contentSize": 267474,
        "type": "file",
        "contentHash": "8eb9c5cb57cf22f01afa77fd32c9cf397eab51d47d909a4102d3186c3ed88f3e",
        "pathLower": "/dbl/accounts/rsjykbr6/17_rsjykbr6_lfs_1.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/17_rsjykbr6_LFs_1.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4yA",
        "name": "7_rsjykbr6_Extreme_4.png",
        "lastModifiedClient": "2024-12-27T20:06:46Z",
        "lastModifiedServer": "2024-12-27T20:06:47Z",
        "rev": "0162a4600a37d57000000013151e9d1",
        "contentSize": 308045,
        "type": "file",
        "contentHash": "cda40e071f5e036957c7013032771eccb58660b2c24f015c086a2ceeb9d8ade3",
        "pathLower": "/dbl/accounts/rsjykbr6/7_rsjykbr6_extreme_4.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/7_rsjykbr6_Extreme_4.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4yQ",
        "name": "19_rsjykbr6_ULTRA_1.png",
        "lastModifiedClient": "2024-12-27T20:06:47Z",
        "lastModifiedServer": "2024-12-27T20:06:47Z",
        "rev": "0162a4600a9172b000000013151e9d1",
        "contentSize": 242349,
        "type": "file",
        "contentHash": "15f7255f236d5190ed2f0624746359fcc7b2527ad06bb67a99a2009f1dbffe9f",
        "pathLower": "/dbl/accounts/rsjykbr6/19_rsjykbr6_ultra_1.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/19_rsjykbr6_ULTRA_1.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4yg",
        "name": "21_rsjykbr6_MedalExchange_1.png",
        "lastModifiedClient": "2024-12-27T20:06:47Z",
        "lastModifiedServer": "2024-12-27T20:06:48Z",
        "rev": "0162a4600b26731000000013151e9d1",
        "contentSize": 249628,
        "type": "file",
        "contentHash": "3e4c90f325ae9f4ae81b6ce4a265cd098b05809ef392879e9a614926278a8bc6",
        "pathLower": "/dbl/accounts/rsjykbr6/21_rsjykbr6_medalexchange_1.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/21_rsjykbr6_MedalExchange_1.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4yw",
        "name": "22_rsjykbr6_MedalExchange_2.png",
        "lastModifiedClient": "2024-12-27T20:06:55Z",
        "lastModifiedServer": "2024-12-27T20:06:55Z",
        "rev": "0162a460127c6d9000000013151e9d1",
        "contentSize": 260951,
        "type": "file",
        "contentHash": "911adb25e4ef1f67ea315d2398f574a781c24983d5ffe6bfdfa828e5d676d6a7",
        "pathLower": "/dbl/accounts/rsjykbr6/22_rsjykbr6_medalexchange_2.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/22_rsjykbr6_MedalExchange_2.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4zA",
        "name": "16_rsjykbr6_Sparking_8.png",
        "lastModifiedClient": "2024-12-27T20:06:55Z",
        "lastModifiedServer": "2024-12-27T20:06:56Z",
        "rev": "0162a46012cc91f000000013151e9d1",
        "contentSize": 309237,
        "type": "file",
        "contentHash": "98466a140c2895117a40439bc15bfcdb83171f5ad56110144c110c1084fdd525",
        "pathLower": "/dbl/accounts/rsjykbr6/16_rsjykbr6_sparking_8.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/16_rsjykbr6_Sparking_8.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4zQ",
        "name": "20_rsjykbr6_MultiZLL_1.png",
        "lastModifiedClient": "2024-12-27T20:06:56Z",
        "lastModifiedServer": "2024-12-27T20:06:56Z",
        "rev": "0162a4601332cca000000013151e9d1",
        "contentSize": 237680,
        "type": "file",
        "contentHash": "716f0984c957ce16605786ade85e8411c9a22dccc15d6bc701bf6111e91f5cfb",
        "pathLower": "/dbl/accounts/rsjykbr6/20_rsjykbr6_multizll_1.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/20_rsjykbr6_MultiZLL_1.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4zg",
        "name": "18_rsjykbr6_ZenkaiAwk_1.png",
        "lastModifiedClient": "2024-12-27T20:06:56Z",
        "lastModifiedServer": "2024-12-27T20:06:56Z",
        "rev": "0162a4601398bb2000000013151e9d1",
        "contentSize": 251716,
        "type": "file",
        "contentHash": "f81d6eae88ea419711a57b8ae1c9c978d81f9a00f257dbde6dba23a9ea2fecc0",
        "pathLower": "/dbl/accounts/rsjykbr6/18_rsjykbr6_zenkaiawk_1.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/18_rsjykbr6_ZenkaiAwk_1.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA4zw",
        "name": "15_rsjykbr6_Sparking_7.png",
        "lastModifiedClient": "2024-12-27T20:07:13Z",
        "lastModifiedServer": "2024-12-27T20:07:13Z",
        "rev": "0162a46023d58ba000000013151e9d1",
        "contentSize": 307700,
        "type": "file",
        "contentHash": "46f935d178187efda02dcc985a55dd96d283fdc9cffdb7421c33a72c7666a709",
        "pathLower": "/dbl/accounts/rsjykbr6/15_rsjykbr6_sparking_7.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/15_rsjykbr6_Sparking_7.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA40A",
        "name": "11_rsjykbr6_Sparking_3.png",
        "lastModifiedClient": "2024-12-27T20:07:14Z",
        "lastModifiedServer": "2024-12-27T20:07:14Z",
        "rev": "0162a460242b813000000013151e9d1",
        "contentSize": 313840,
        "type": "file",
        "contentHash": "482d1f8345fc3d6ac7b62dcf951237d9b2f7ec2b942607f90f489dcde91d0405",
        "pathLower": "/dbl/accounts/rsjykbr6/11_rsjykbr6_sparking_3.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/11_rsjykbr6_Sparking_3.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA40Q",
        "name": "1_rsjykbr6_MainScreen.png",
        "lastModifiedClient": "2024-12-27T20:07:14Z",
        "lastModifiedServer": "2024-12-27T20:07:14Z",
        "rev": "0162a46024aa764000000013151e9d1",
        "contentSize": 291446,
        "type": "file",
        "contentHash": "4ca435acd56c67c94935ced86145bf09c54a41b798a51005592bcd012859033a",
        "pathLower": "/dbl/accounts/rsjykbr6/1_rsjykbr6_mainscreen.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/1_rsjykbr6_MainScreen.png",
        "isDownloadable": true
      },
      {
        "id": "id:wvTgQWqrar0AAAAAAAA40g",
        "name": "8_rsjykbr6_Extreme_5.png",
        "lastModifiedClient": "2024-12-27T20:07:15Z",
        "lastModifiedServer": "2024-12-27T20:07:15Z",
        "rev": "0162a460253ed82000000013151e9d1",
        "contentSize": 309039,
        "type": "file",
        "contentHash": "3e42a04e503e7e1aea3ab71ee89f8ac7f421752fcf3a902523f2bf0738d2c9c4",
        "pathLower": "/dbl/accounts/rsjykbr6/8_rsjykbr6_extreme_5.png",
        "pathDisplay": "/DBL/Accounts/rsjykbr6/8_rsjykbr6_Extreme_5.png",
        "isDownloadable": true
      }
    ]
  }
}

To Reproduce

Steps to Reproduce (Code Mode)

  1. Create a Sort node in the workflow.
  2. Use the following custom sort code:
    const fieldName = 'name';
    
    function getNumericPrefix(fileName) {
        if (!fileName || typeof fileName !== 'string') {
            return Infinity; // Handle invalid fileName gracefully
        }
        const match = fileName.match(/^(\d+)_/);
        return match ? parseInt(match[1], 10) : Infinity; // Return Infinity if no match
    }
    
    try {
        const aPrefix = getNumericPrefix(a.json[fieldName]);
        const bPrefix = getNumericPrefix(b.json[fieldName]);
    
        if (aPrefix < bPrefix) {
            return -1;
        }
        if (aPrefix > bPrefix) {
            return 1;
        }
        return 0;
    } catch (error) {
        console.error('Error in sort function:', error);
        return 0;
    }
  3. Run the workflow with items that include the name field, formatted as <number>_filename (e.g., 123_file.txt).
  4. Observe intermittent failures with the error message.

On Simple mode just use same mode with cancelling the code mode to Simple.

Expected behavior

I should use Simple mode and it sort the items by numbers
1_
2_
3_
etc...

However, just want to mention that sometimes the code mode working. and sometimes giving the provided error. This report not for looking for solution i already used the code node to fix, but wanted to report it to be known 👍.

Operating System

docker (self-hosted)

n8n Version

1.73.1

Node.js Version

20.18.0

Database

PostgreSQL

Execution mode

main (default)

@Joffcom
Copy link
Member

Joffcom commented Dec 28, 2024

Hey @ARHAEEM,

We have created an internal ticket to look into this which we will be tracking as "N8N-8016"

@Joffcom Joffcom added the in linear Issue or PR has been created in Linear for internal review label Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in linear Issue or PR has been created in Linear for internal review
Projects
None yet
Development

No branches or pull requests

2 participants