n8n-io / n8n

Free and source-available fair-code licensed workflow automation tool. Easily automate tasks across different services.
https://n8n.io
Other
45.52k stars 6.27k forks source link

n8n crashes on start if LocalFileTrigger option ignored is an empty string #4824

Closed marzn closed 1 year ago

marzn commented 1 year ago

Describe the bug

If a LocalFileTrigger is configured with the ignore option but no input (default is an empty string) or the input is deleted, but the ignore option is not deleted, this will result in a crash of n8n. n8n is even not able to restart, because the LocalFileTrigger is executed on startup.

Log / Stacktrace:

/usr/local/lib/node_modules/n8n/node_modules/picomatch/lib/picomatch.js:48
    throw new TypeError('Expected pattern to be a non-empty string');
          ^

TypeError: Expected pattern to be a non-empty string
    at picomatch (/usr/local/lib/node_modules/n8n/node_modules/picomatch/lib/picomatch.js:48:11)
    at createPattern (/usr/local/lib/node_modules/n8n/node_modules/anymatch/index.js:27:18)
    at /usr/local/lib/node_modules/n8n/node_modules/anymatch/index.js:91:21
    at Array.map (<anonymous>)
    at anymatch (/usr/local/lib/node_modules/n8n/node_modules/anymatch/index.js:91:6)
    at FSWatcher._isIgnored (/usr/local/lib/node_modules/n8n/node_modules/chokidar/index.js:776:25)
    at NodeFsHandler._addToNodeFs (/usr/local/lib/node_modules/n8n/node_modules/chokidar/lib/nodefs-handler.js:581:16)
    at /usr/local/lib/node_modules/n8n/node_modules/chokidar/index.js:451:47
    at Array.map (<anonymous>)
    at FSWatcher.add (/usr/local/lib/node_modules/n8n/node_modules/chokidar/index.js:450:13)
    at watch (/usr/local/lib/node_modules/n8n/node_modules/chokidar/index.js:969:11)
    at Object.trigger (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/LocalFileTrigger/LocalFileTrigger.node.js:179:46)
    at Workflow.runTrigger (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:570:33)
    at ActiveWorkflows.add (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/ActiveWorkflows.js:26:50)
    at async ActiveWorkflowRunner.add (/usr/local/lib/node_modules/n8n/dist/ActiveWorkflowRunner.js:475:17)
    at async ActiveWorkflowRunner.init (/usr/local/lib/node_modules/n8n/dist/ActiveWorkflowRunner.js:72:21)
    at async /usr/local/lib/node_modules/n8n/dist/commands/start.js:274:17
    at async Start.run (/usr/local/lib/node_modules/n8n/dist/commands/start.js:116:9)
    at async Start._run (/usr/local/lib/node_modules/n8n/node_modules/@oclif/command/lib/command.js:43:20)
    at async Config.runCommand (/usr/local/lib/node_modules/n8n/node_modules/@oclif/config/lib/config.js:173:24)
    at async Main.run (/usr/local/lib/node_modules/n8n/node_modules/@oclif/command/lib/main.js:28:9)
    at async Main._run (/usr/local/lib/node_modules/n8n/node_modules/@oclif/command/lib/command.js:43:20)

To Reproduce Steps to reproduce the behavior:

  1. Add 'LocalFileTrigger' node
  2. Select 'Trigger On' -> 'Changes to s Specific File'
  3. Insert some path for 'File to Watch', non existing files are valid, so you may insert something like '/tmp/tmp.txt'
  4. Click 'Add Option'
  5. Click 'Ignore'
  6. Save workflow
  7. Activate workflow

Expected behavior

n8n should not crash (on startup).

Environment (please complete the following information):

Additional context

Joffcom commented 1 year ago

Hey @marzn,

Thanks for the report and the work you have done putting in the PR to fix this one, I have given it a test and with your fix it is working as it should. Nice work 🙌🏻

janober commented 1 year ago

Fix got released with n8n@0.206.1