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

Upon error, check for new version and suggest to upgrade #49

Open
anibalsolon opened this issue Jan 2, 2022 · 3 comments
Open

Upon error, check for new version and suggest to upgrade #49

anibalsolon opened this issue Jan 2, 2022 · 3 comments

Comments

@anibalsolon
Copy link
Member

When an unhandled exception happen, check if the current installed version is the last one. The check should fail silently and timeout quick. Print out the upgrade command in case the version is older than what's published in npm.

@soichih
Copy link
Contributor

soichih commented Jan 3, 2022

Exceptions/errors could happen due to many different reasons (not just out-dated CLI), but the bottom line is that, user should never see "unhandled exception"; CLI should be updated with proper try/catch in various exception throwing sections of the code.

I do think it's a good idea to always check for outdated CLI installation upon execution, and display warning messages. I think CLI can download the package.json from the master branch of this repo and see if it matches the version listed in package.json

import fetch from 'node-fetch';
import fs from 'fs';

async function check() {
    const masterPackage = await fetch("https://raw.githubusercontent.com/brainlife/cli/master/package.json").then(res=>res.json());
    const thisPackage = JSON.parse(fs.readFileSync("package.json"));
    if(thisPackage.version != masterPackage.version) {
        console.log("master branch version doesn't match this the installed version");
    }
}

check();

By the way, if a user wants to ensure that they always use the latest version of CLI, they can add this to .bashrc

function bl {
    singularity run docker://brainlife/cli $@
}

singularity makes sure that it has the latest version of docker container cached locally and it will download the latest version if it's not up-to-date. See https://brainlife.io/docs/cli/install/#docker-container

@anibalsolon
Copy link
Member Author

Handling the errors / catch-all would be very good, more user friendly

@soichih
Copy link
Contributor

soichih commented Jun 29, 2022

Actually I shouldn't just look at master branch's package.json. I should somehow query the current version from npmjs

npm show brainlife version

and compare it against the version in ./package.json. If we can assume that brainlife CLI is always installed via npm, and if npm command is available, we can just run the above command to show the current release version, but I am not sure if we can make that assumption or not

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

No branches or pull requests

2 participants