-
Notifications
You must be signed in to change notification settings - Fork 970
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
Generators: rollback changes if an error occurs #82
Comments
ENVIRONMENT
OBSERVATION Running the Posts generation example from the tutorial, only some files are generated:
One file already existed from a prior run (=> me not cleaning everything up). The step with "X" (Writing SUGGESTION Possibly an Some form of all-or-nothing generation (with awareness of |
We do have a I've actually got a fix for this specific problem (it will just skip Ideally we want a more interactive |
Additional feedback FWIW. Assuming |
@cannikin Ok to close this one out? |
@thedavidprice This was meant to be a feature/enhancement issue but turned into a bug report. haha I think this IS a feature we want at some point: right now if a generator fails for some reason you'll have half the files created and half not. |
@cannikin do you think the Destroy command covers this feature? It's not 1-to-1, but maybe this feature could leverage Destroy -- e.g. if error occurs it would prompt to run cleanup via Destroy. |
Hmmm, good question. I'm not sure what happens if some of the files don't exist when you run the destroy command, but it would be pretty ironic if then that blew up! But in theory it does know how to undo everything that the generate command did... I can try to test this out at some point but it may be a few days until I get around to it! |
An update on this: the presence of |
@cannikin Do think there still interest in this? I do think it would be good to rollback on an error by default. Take #6840 as a recent example of when it would have been much clearer to the user an error occurred if we'd have rolled back and we wouldn't have ended up in a broken state. If the destroy commands know how to revert the changes of the associated generate command then it might be possible just to add a listr2 rollback task. This addition of the rollback would probably only need to occur when the helper function: redwood/packages/cli/src/commands/generate/helpers.js Lines 206 to 222 in 2bc3a54
|
I’d love to do it, but my worry is that the destroy commands haven’t really been kept up to date…I’d be surprised if they all still worked.To really do it the right way I figured the generators really need to be refactored to keep track of what they’re creating so they can automatically be destroyed or rolled back without maintaining separate create/destroy commands like we have now. But, if the destroy commands ARE in sync then you’re right: in case of any error just run the destroy command and we’re good to go!On Nov 20, 2022, at 8:38 AM, Josh GM Walker ***@***.***> wrote:
@cannikin Do think there still interest in this? I do think it would be good to rollback on an error by default.
Take #6840 as a recent example of when it would have been much clearer to the user an error occurred if we'd have rolled back and we wouldn't have ended up in a broken state.
If the destroy commands know how to revert the changes of the associated generate command then it might be possible just to add a listr2 rollback task. This addition of the rollback would probably only need to occur when the helper function:
https://github.com/redwoodjs/redwood/blob/2bc3a544167538da5c12e66902f6a385f4a374d4/packages/cli/src/commands/generate/helpers.js#L206-L222 Perhaps it might not be a lot of work to implement this feature, assuming the destroy commands can revert.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Excellent that's what I was hoping to learn, if these destroy commands were working well and if they were the preferred direction forward. Since they don't seem to be loved I might have a think about how it could be done with as minimal a change to the current generators as possible and without relying on these destroy commands. Thanks! |
Right now if an error occurs while the generators are running anything that was already done (create files, append routes) will be left in place.
We should keep track of all changes that are made and roll them back if an error occurs during a generator.
The text was updated successfully, but these errors were encountered: