mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix getting error message for displaying to the user
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
793b20576c
commit
a4a13500a0
@ -311,10 +311,7 @@ export class ExtensionDiscovery {
|
|||||||
*/
|
*/
|
||||||
protected async getByManifest(manifestPath: string, { isBundled = false } = {}): Promise<InstalledExtension | null> {
|
protected async getByManifest(manifestPath: string, { isBundled = false } = {}): Promise<InstalledExtension | null> {
|
||||||
try {
|
try {
|
||||||
console.log(manifestPath);
|
|
||||||
const manifest = await fse.readJson(manifestPath);
|
const manifest = await fse.readJson(manifestPath);
|
||||||
|
|
||||||
console.log(manifest);
|
|
||||||
const installedManifestPath = this.getInstalledManifestPath(manifest.name);
|
const installedManifestPath = this.getInstalledManifestPath(manifest.name);
|
||||||
const isEnabled = isBundled || extensionsStore.isEnabled(installedManifestPath);
|
const isEnabled = isBundled || extensionsStore.isEnabled(installedManifestPath);
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,28 @@ import { Spinner } from "../spinner/spinner";
|
|||||||
import { TooltipPosition } from "../tooltip";
|
import { TooltipPosition } from "../tooltip";
|
||||||
import { ExtensionInstallationState, ExtensionInstallationStateStore } from "./extension-install.store";
|
import { ExtensionInstallationState, ExtensionInstallationStateStore } from "./extension-install.store";
|
||||||
|
|
||||||
|
function getMessageFromError(error: any): string {
|
||||||
|
if (!error || typeof error !== "object") {
|
||||||
|
return "an error has occured";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.message) {
|
||||||
|
return String(error.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.err) {
|
||||||
|
return String(error.err);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawMessage = String(error);
|
||||||
|
|
||||||
|
if (rawMessage === String({})) {
|
||||||
|
return "an error has occured";
|
||||||
|
}
|
||||||
|
|
||||||
|
return rawMessage;
|
||||||
|
}
|
||||||
|
|
||||||
interface InstallRequest {
|
interface InstallRequest {
|
||||||
fileName: string;
|
fileName: string;
|
||||||
filePath?: string;
|
filePath?: string;
|
||||||
@ -58,9 +80,10 @@ async function uninstallExtension(extensionId: LensExtensionId, manifest: LensEx
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Notifications.error(
|
const message = getMessageFromError(error);
|
||||||
<p>Uninstalling extension <b>{displayName}</b> has failed: <em>{error?.message ?? error?.toString() ?? ""}</em></p>
|
|
||||||
);
|
logger.info(`[EXTENSION-UNINSTALL]: uninstalling ${displayName} has failed: ${error}`, { error });
|
||||||
|
Notifications.error(<p>Uninstalling extension <b>{displayName}</b> has failed: <em>{message}</em></p>);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -102,7 +125,10 @@ async function preloadExtension({ fileName, data, filePath }: InstallRequest, {
|
|||||||
return { filePath, data, fileName };
|
return { filePath, data, fileName };
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
if (showError) {
|
if (showError) {
|
||||||
Notifications.error(`Error while reading "${filePath}": ${String(error)}`);
|
const message = getMessageFromError(error);
|
||||||
|
|
||||||
|
logger.info(`[EXTENSION-INSTALL]: preloading ${filePath} has failed: ${message}`, { error });
|
||||||
|
Notifications.error(`Error while reading "${filePath}": ${message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,10 +188,13 @@ async function createTempFilesAndValidate(request: InstallRequestPreloaded, { sh
|
|||||||
fse.unlink(tempFile).catch(noop); // remove invalid temp package
|
fse.unlink(tempFile).catch(noop); // remove invalid temp package
|
||||||
|
|
||||||
if (showErrors) {
|
if (showErrors) {
|
||||||
|
const message = getMessageFromError(error);
|
||||||
|
|
||||||
|
logger.info(`[EXTENSION-INSTALLATION]: installing ${request.fileName} has failed: ${message}`, { error });
|
||||||
Notifications.error(
|
Notifications.error(
|
||||||
<div className="flex column gaps">
|
<div className="flex column gaps">
|
||||||
<p>Installing <em>{request.fileName}</em> has failed, skipping.</p>
|
<p>Installing <em>{request.fileName}</em> has failed, skipping.</p>
|
||||||
<p>Reason: <em>{String(error)}</em></p>
|
<p>Reason: <em>{message}</em></p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -215,9 +244,10 @@ async function unpackExtension(request: InstallRequestValidated, disposeDownload
|
|||||||
<p>Extension <b>{displayName}</b> successfully installed!</p>
|
<p>Extension <b>{displayName}</b> successfully installed!</p>
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Notifications.error(
|
const message = getMessageFromError(error);
|
||||||
<p>Installing extension <b>{displayName}</b> has failed: <em>{error}</em></p>
|
|
||||||
);
|
logger.info(`[EXTENSION-INSTALLATION]: installing ${request.fileName} has failed: ${message}`, { error });
|
||||||
|
Notifications.error(<p>Installing extension <b>{displayName}</b> has failed: <em>{message}</em></p>);
|
||||||
} finally {
|
} finally {
|
||||||
// Remove install state once finished
|
// Remove install state once finished
|
||||||
ExtensionInstallationStateStore.clearInstalling(id);
|
ExtensionInstallationStateStore.clearInstalling(id);
|
||||||
@ -267,7 +297,7 @@ async function requestInstall(request: InstallRequest, d?: Disposer): Promise<vo
|
|||||||
|
|
||||||
if (!folderExists) {
|
if (!folderExists) {
|
||||||
// install extension if not yet exists
|
// install extension if not yet exists
|
||||||
unpackExtension(validatedRequest, dispose);
|
await unpackExtension(validatedRequest, dispose);
|
||||||
} else {
|
} else {
|
||||||
// otherwise confirmation required (re-install / update)
|
// otherwise confirmation required (re-install / update)
|
||||||
const removeNotification = Notifications.info(
|
const removeNotification = Notifications.info(
|
||||||
@ -285,13 +315,13 @@ async function requestInstall(request: InstallRequest, d?: Disposer): Promise<vo
|
|||||||
if (await uninstallExtension(validatedRequest.id, validatedRequest.manifest)) {
|
if (await uninstallExtension(validatedRequest.id, validatedRequest.manifest)) {
|
||||||
await unpackExtension(validatedRequest, dispose);
|
await unpackExtension(validatedRequest, dispose);
|
||||||
} else {
|
} else {
|
||||||
disposer();
|
dispose();
|
||||||
}
|
}
|
||||||
}} />
|
}} />
|
||||||
</div>,
|
</div>,
|
||||||
{
|
{
|
||||||
onClose() {
|
onClose() {
|
||||||
disposer();
|
dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -318,12 +348,13 @@ async function installOnDrop(files: File[]) {
|
|||||||
|
|
||||||
async function installFromUrlOrPath(installPath: string) {
|
async function installFromUrlOrPath(installPath: string) {
|
||||||
const fileName = path.basename(installPath);
|
const fileName = path.basename(installPath);
|
||||||
|
let disposer: Disposer;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// install via url
|
// install via url
|
||||||
// fixme: improve error messages for non-tar-file URLs
|
// fixme: improve error messages for non-tar-file URLs
|
||||||
if (InputValidators.isUrl.validate(installPath)) {
|
if (InputValidators.isUrl.validate(installPath)) {
|
||||||
const disposer = ExtensionInstallationStateStore.startPreInstall();
|
disposer = ExtensionInstallationStateStore.startPreInstall();
|
||||||
const { promise: filePromise } = downloadFile({ url: installPath, timeout: 60000 /*1m*/ });
|
const { promise: filePromise } = downloadFile({ url: installPath, timeout: 60000 /*1m*/ });
|
||||||
const data = await filePromise;
|
const data = await filePromise;
|
||||||
|
|
||||||
@ -334,9 +365,12 @@ async function installFromUrlOrPath(installPath: string) {
|
|||||||
await requestInstall({ fileName, filePath: installPath });
|
await requestInstall({ fileName, filePath: installPath });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Notifications.error(
|
const message = getMessageFromError(error);
|
||||||
<p>Installation has failed: <b>{String(error)}</b></p>
|
|
||||||
);
|
logger.info(`[EXTENSION-INSTALL]: installation has failed: ${message}`, { error, installPath });
|
||||||
|
Notifications.error(<p>Installation has failed: <b>{message}</b></p>);
|
||||||
|
} finally {
|
||||||
|
disposer?.();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user