Fail Gracefully When Installed Binaries Present
HashWarlock opened this issue · comments
Currently when a user runs the yarn devphase init
twice the second time will be met with a panic!
though this should just return with a log stating that the binaries are already downloaded and the project directory is already setup and valid. This becomes a problem for the Swanky CLI integration and will return an error like below with ./bin/dev phala init
└─[$]> ./bin/dev phala init new-project
? Which contract template should we use? pink
? Which contract template should we use? sample_oracle
? What should we name your contract? sample_oracle
? What is your name? hashwarlock
? What is your email? hashwarlock@phala.network
? Do you want to download Phala node components for local testnet? Yes
Initializing
✔ Copying template files OK
✔ Processing templates OK
✔ Initializing git OK
✔ Setting up repo... OK
✖ Error Downloading Phala binaries for local testnet...
When running the yarn devphase init
in the directory that is created successfully a user will see an error message like below:
└─[$]> yarn devphase init
yarn run v1.22.17
$ /home/hashwarlock/Projects/Phala/Workshop/Sub0/swanky-plugin-phala/new-project/node_modules/.bin/devphase init
[Init] Initiation
/home/hashwarlock/Projects/Phala/Workshop/Sub0/swanky-plugin-phala/new-project/node_modules/devphase/dist/cli/index.js:959
throw new Exception("Project already initiated", 1667764070755);
^
Throwable: Project already initiated
at Initializer.init (/home/hashwarlock/Projects/Phala/Workshop/Sub0/swanky-plugin-phala/new-project/node_modules/devphase/dist/cli/index.js:959:17)
at async command (/home/hashwarlock/Projects/Phala/Workshop/Sub0/swanky-plugin-phala/new-project/node_modules/devphase/dist/cli/index.js:992:3) {
code: 1667764070755
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
There can be a couple solutions on this where we return instead of throw an exception or overwrite the files with the latest binaries & packages. Let me know if you have other ideas on how to handle this.
Code where exception thrown:
devphase/src/service/project/Initializer.ts
Lines 32 to 36 in 69813b8
Fixed in v0.0.30