Skip to content

Commit 9e65048

Browse files
committed
feat(cli/update): improve version not found error message, and throw error message when installing same version with -v (must use -r)
1 parent 38b9765 commit 9e65048

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

bin/install_cli

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,19 @@ fi
239239
DOWNLOAD_URL="https://storage.googleapis.com/genkit-assets-cli/$channel/$MACHINE/latest"
240240
echo "-- Downloading binary from $DOWNLOAD_URL"
241241

242-
# We use "curl" to download the binary with a flag set to follow redirects
243-
# (GitHub download URLs redirect to CDNs) and a flag to show a progress bar.
244-
curl -o "/tmp/genkit_standalone.tmp" --fail -L --progress-bar $DOWNLOAD_URL
245-
if [ $? -ne 0 ]; then
246-
echo "Something went wrong. Failed to download binary from $DOWNLOAD_URL"
247-
echo "Please file a bug with your system information on GitHub."
248-
echo "https://github.com/firebase/genkit/"
242+
# Download the binary, but capture HTTP status code to detect 404s (package not found)
243+
HTTP_STATUS=$(curl -w "%{http_code}" -o "/tmp/genkit_standalone.tmp" --fail -L --progress-bar "$DOWNLOAD_URL" 2>/dev/null)
244+
CURL_EXIT_CODE=$?
245+
246+
if [ $CURL_EXIT_CODE -ne 0 ] || [ "$HTTP_STATUS" = "404" ]; then
247+
# Check if the user requested a specific version (by checking if DOWNLOAD_URL contains /v[0-9])
248+
if [[ "$DOWNLOAD_URL" =~ /v[0-9]+\.[0-9]+\.[0-9]+/ ]] || [[ "$HTTP_STATUS" = "404" ]]; then
249+
echo "Package not found. The requested version does not exist for your platform."
250+
else
251+
echo "Something went wrong. Failed to download binary from $DOWNLOAD_URL"
252+
echo "Please file a bug with your system information on GitHub."
253+
echo "https://github.com/firebase/genkit/"
254+
fi
249255

250256
send_analytics_event download_failure
251257

genkit-tools/cli/src/commands/update.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ async function downloadAndInstall(version: string): Promise<void> {
250250

251251
// If not running from a binary, we should install using package manager
252252
if (!runtime.isCompiledBinary) {
253+
// Check if the requested version is available on npm
254+
const availableVersions = await getAvailableVersionsFromNpm();
255+
if (!availableVersions.includes(version.replace(/^v/, ''))) {
256+
logger.error(
257+
`Version ${clc.bold(version)} is not available on npm.`
258+
);
259+
process.exit(1);
260+
}
261+
253262
const pm = await inquirePackageManager();
254263
let command = '';
255264

@@ -260,7 +269,7 @@ async function downloadAndInstall(version: string): Promise<void> {
260269
}
261270

262271
logger.info(`Running using ${pm?.type}, downloading using ${pm?.type}...`);
263-
execSync(command);
272+
execSync(command, { stdio: 'inherit' });
264273
logger.info(
265274
`${clc.green('✓')} Successfully updated to ${clc.bold(version)}`
266275
);
@@ -441,6 +450,13 @@ export const update = new Command('update')
441450

442451
logger.info(`${clc.yellow('!')} Reinstalling v${clc.bold(version)}...`);
443452
} else if (version) {
453+
if (version === currentVersion) {
454+
logger.info(
455+
`${clc.green('✓')} Already using version v${clc.bold(version)}.`
456+
);
457+
return;
458+
}
459+
444460
logger.info(`Installing v${clc.bold(version)}...`);
445461
} else {
446462
logger.info('Checking for updates...');

0 commit comments

Comments
 (0)