From 100f8211189ff6f091c045bfd88a1e714aa9a1fe Mon Sep 17 00:00:00 2001 From: Max Howell Date: Tue, 17 Oct 2023 09:21:05 -0400 Subject: [PATCH] Fixes #812 --- src/app.ts | 12 ++++++++++-- src/err-handler.ts | 10 +++++++++- src/modes/install.ts | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/app.ts b/src/app.ts index 4f7b9ac5..21a0da42 100644 --- a/src/app.ts +++ b/src/app.ts @@ -19,6 +19,7 @@ import help from "./modes/help.ts" import repl from "./modes/repl.ts" import env from "./modes/env.ts" import x from "./modes/x.ts" +import { AmbiguityError } from "./utils/error.ts" const { usePantry, useSync } = hooks const { flatmap } = utils @@ -66,8 +67,15 @@ export default async function({ flags, ...opts }: Args, logger_prefix?: string) } } break case 'install': - await ensure_pantry() - await install(await Promise.all(opts.args.map(x => parse_pkg_str(x, {latest: 'ok'})))) + try { + await ensure_pantry() + await install(await Promise.all(opts.args.map(x => parse_pkg_str(x, {latest: 'ok'})))) + } catch (err) { + if (err instanceof AmbiguityError) { + err.ctx = 'install' + } + throw err + } break case 'deintegrate': await integrate('uninstall', opts) diff --git a/src/err-handler.ts b/src/err-handler.ts index cb439e17..6085bc2e 100644 --- a/src/err-handler.ts +++ b/src/err-handler.ts @@ -24,12 +24,20 @@ export default function(err: Error) { render('pantry error', err.message, [[JSON.stringify(err.ctx)]], 'pantry-error') } else if (err instanceof AmbiguityError) { const args = Deno.args.join(' ') - const projects = err.projects.map(p => [` %c pkgx +${p} ${args} %c`, 'background-color: black; color: white', 'color: initial']) + const projects = (() => { + if (err.ctx != 'install') { + return err.projects.map(p => [` %c pkgx +${p} ${args} %c`, 'background-color: black; color: white', 'color: initial']) + } else { + return err.projects.map(p => [` %c pkgx install ${p} %c`, 'background-color: black; color: white', 'color: initial']) + } + })() + render('multiple projects provide:', err.arg0, [ ['pls be more specific:'], [], ...projects, [] ] , 'ambiguous-pkgspec') + } else if (err instanceof ProvidesError) { render('nothing provides:', err.arg0, [ ['we haven’t pkgd this yet. %ccan you?', 'font-weight: bold'] diff --git a/src/modes/install.ts b/src/modes/install.ts index 7aa47292..4509b58b 100644 --- a/src/modes/install.ts +++ b/src/modes/install.ts @@ -13,6 +13,7 @@ export default async function(pkgs: PackageRequirement[]) { try { await write(usrlocal, pkgs) } catch (err) { + //FIXME we should check if /usr/local/bin is writable, but were having trouble with that if (err instanceof Deno.errors.PermissionDenied) { await write(Path.home().join(".local/bin"), pkgs) } else {