Skip to content

Commit

Permalink
Better error management
Browse files Browse the repository at this point in the history
  • Loading branch information
vrde committed May 9, 2019
1 parent a9b8fb2 commit 670a09e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli.js
Expand Up @@ -34,7 +34,7 @@ program
.option(
"-e, --execute <command>",
"Start ethnode, execute command, and exit ethnode (useful for testing)."
)
);

program.version(packageJson.version);

Expand Down
6 changes: 5 additions & 1 deletion get_geth.sh
Expand Up @@ -3,12 +3,16 @@

# Note: $HOMEDIR is defined in main.js, check it out

set -e

PLATFORM=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

VERSION=$(curl -s https://api.github.com/repos/ethereum/go-ethereum/releases/latest | python -c "import sys, json; print(json.load(sys.stdin)['tag_name'])")
COMMIT=$(curl -s https://api.github.com/repos/ethereum/go-ethereum/commits/${VERSION} | python -c "import sys, json; print(json.load(sys.stdin)['sha'])")
NAME="geth-${PLATFORM}-amd64-${VERSION:1}-${COMMIT:0:8}"
DOWNLOAD_URL="https://gethstore.blob.core.windows.net/builds/${NAME}.tar.gz"
curl ${DOWNLOAD_URL} | tar -Oxzf - ${NAME}/geth > ${HOMEDIR}/geth
TMP_FILE=$(mktemp)
curl --fail ${DOWNLOAD_URL} | tar -Oxzf - ${NAME}/geth > ${TMP_FILE}
mv ${TMP_FILE} ${HOMEDIR}/geth
chmod +x ${HOMEDIR}/geth
13 changes: 12 additions & 1 deletion main.js
Expand Up @@ -87,10 +87,17 @@ function downloadClient(client, workdir) {

if (!fs.existsSync(paths.binary)) {
console.log(`Download latest ${client} version, please wait.`);
spawnSync(path.join(__dirname, `get_${client}.sh`), {
const childResult = spawnSync(path.join(__dirname, `get_${client}.sh`), {
env: { HOMEDIR },
stdio: "inherit"
});
if (childResult.status !== 0) {
console.log(
`Error downloading ${client}, this might be temporary, ` +
`try again later.`
);
process.exit(childResult.status);
}
}
}

Expand Down Expand Up @@ -131,6 +138,10 @@ function provide(client, workdir, allocate, execute, loggingOptions) {
}
);
if (childResult.status !== 0) {
console.log(
`Error running ${paths.binary}, run it manually to check if it ` +
`works or not. If it doesn't, remove it and run ethnode again.`
);
process.exit(childResult.status);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -6,7 +6,7 @@
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"install": "ethnode -d"
"postinstall": "./cli.js -d"
},
"bin": "./cli.js",
"author": "vrde",
Expand Down

0 comments on commit 670a09e

Please sign in to comment.