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

Remove triggers that have a malformed path #3121

Merged

Conversation

AdamJohnSwan
Copy link

Original Issue

A malformed path would crash the program on startup because the Directory.CreateDirectory method would throw an unhandled exception. This is a bigger issue if the workflow is persistent since the trigger will get created but there isn't a way to remove it if something goes wrong. Meaning that if you use a WatchDirectory activity with an invalid path the project will fail to start until you change or remove the trigger in your database.

How to create the original error

I used the project ElsaDashboard.Samples.AspNetCore.Monolith in the samples directory for testing since it already has Elsa server setup with SQLite as the persistence provider.

I added file activities using AddFileActivities() in the Startup file and I started up the project. I created a new workflow that only has one activity: a WatchDirectory activity and made the path C:\Te|st.

I am using Windows and this is an invalid path due to the |. If you are running something Unix based try /test///directory. The triple slashes should throw the same exception.

Publish this workflow and you will see a wave of exceptions fill the console. Now, shutdown the project and restart it. It will fail to start and cannot be restarted until you remove or change the trigger and the workflow definition in the SQLite database.


This PR is for two things:

  1. Provide a service that allows a user to remove a trigger
  2. Handles the IO or Argument exception thrown by the Directory.CreateDirectory method and removes the trigger that caused the exception.

To Test

Recreate the situation I described above using the ElsaDashboard.Samples.AspNetCore.Monolith project. This time though the exception will be logged to the console and the project can still be started. Meaning the user can edit the offending workflow from the UI.

I also tested this with the Builder API. This is the workflow I made:

public class WatchDirTest: IWorkflow
    {
        public void Build(IWorkflowBuilder builder)
        {
            builder 
                .WatchDirectory(setup => setup
                    .WithPath("C:\Te|st")
                    .WithPattern("*.txt"));
        }
    }

It will achieve the same result as when the designer is used. Even if you change the value of WithPath to something valid the trigger with the offending path is still there and the project will fail to start.

…r. This is so the file system watcher does not try to create directory names that are malformed.
…ce if the path for the file to watch is invalid.
@dnfadmin
Copy link

dnfadmin commented Jun 8, 2022

CLA assistant check
All CLA requirements met.

@sfmskywalker
Copy link
Member

Thanks @AdamJohnSwan !

@sfmskywalker sfmskywalker merged commit 9006904 into elsa-workflows:master Jun 13, 2022
@AdamJohnSwan AdamJohnSwan deleted the FileSystemWatchMalformedUri branch June 13, 2022 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants