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.
ENVIRONMENT
$ yarn rw --version
0.0.1-alpha.31
OBSERVATION
Running the Posts generation example from the tutorial, only some files are generated:
$ yarn rw g scaffold post
❯ Generating scaffold files...
✔ Writing `./api/src/graphql/posts.sdl.js`...
✔ Writing `./api/src/services/posts/posts.js`...
✔ Writing `./api/src/services/posts/posts.mdx`...
✔ Writing `./api/src/services/posts/posts.test.js`...
✖ Writing `./web/src/scaffold.css`...
→ /Users/chris/proj/aw-redwood/aw/web/src/scaffold.css already exists.
Writing `./web/src/layouts/PostsLayout/PostsLayout.js`...
Writing `./web/src/pages/EditPostPage/EditPostPage.js`...
Writing `./web/src/pages/PostPage/PostPage.js`...
Writing `./web/src/pages/PostsPage/PostsPage.js`...
Writing `./web/src/pages/NewPostPage/NewPostPage.js`...
Writing `./web/src/components/EditPostCell/EditPostCell.js`...
Writing `./web/src/components/Post/Post.js`...
Writing `./web/src/components/PostCell/PostCell.js`...
Writing `./web/src/components/PostForm/PostForm.js`...
Writing `./web/src/components/Posts/Posts.js`...
Writing `./web/src/components/PostsCell/PostsCell.js`...
Writing `./web/src/components/NewPost/NewPost.js`...
Adding scaffold routes...
Adding scaffold asset imports...
✨ Done in 1.20s.
One file already existed from a prior run (=> me not cleaning everything up). The step with "X" (Writing ./web/src/scaffold.css...) failed because the file already existed. The files that were generated before the "X" do exist on disk -- but aren't useful because they depend on files that come later. The files that follow the "X" do not exist on disk, although the CLI output does say "Writing ..." and no per-line error message.
SUGGESTION
Possibly an --overwrite flag to allow clobber of previous generation runs.
Some form of all-or-nothing generation (with awareness of --overwrite) would be best. Hard to diagnose and fix either a partial generation (1st gen) or partial overwrite (2nd/later gen).
We do have a --force option that will overwrite files if they exist!
I've actually got a fix for this specific problem (it will just skip scaffold.css if it already exists) waiting in a PR.
Ideally we want a more interactive Do you want to overwrite? (y/n/a) for each file but that's for the future!
Additional feedback FWIW.
Assuming yarn rw g scaffold foo will be run many times, it will always fail after the first run, due to the existence of scaffold.css, leaving the debris of an incomplete scaffold generation.
@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!
Most helpful comment
We do have a
--forceoption that will overwrite files if they exist!I've actually got a fix for this specific problem (it will just skip
scaffold.cssif it already exists) waiting in a PR.Ideally we want a more interactive
Do you want to overwrite? (y/n/a)for each file but that's for the future!