Skip to content

Commit

Permalink
Add notification on Mops / Vessel package configuration error (#240)
Browse files Browse the repository at this point in the history
* Add notification for error in Mops / Vessel configuration

* Add 'View logs' button to error message

* Adjust error message detail rendering
  • Loading branch information
rvanasa committed Aug 26, 2023
1 parent 24a58a8 commit dfb5480
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/common/connectionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ export const DEPLOY_PLAYGROUND_MESSAGE =
export interface NotifyDeployParams {
message: string;
}

export const ERROR_MESSAGE = new NotificationType<NotifyErrorParams>(
'vscode-motoko/notify-error',
);

export interface NotifyErrorParams {
message: string;
detail?: string | undefined;
}
10 changes: 10 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import * as which from 'which';
import {
DEPLOY_PLAYGROUND,
DEPLOY_PLAYGROUND_MESSAGE,
ERROR_MESSAGE,
TEST_FILE_REQUEST,
TestParams,
TestResult,
Expand Down Expand Up @@ -326,6 +327,15 @@ function restartLanguageServer(
serverOptions,
clientOptions,
);
client.onNotification(ERROR_MESSAGE, async ({ message, detail }) => {
const item = await window.showErrorMessage(
detail ? `${message}\n${detail}` : message,
'View logs',
);
if (item === 'View logs') {
client.outputChannel.show();
}
});
client.start().catch((err) => console.error(err.stack || err));
context.subscriptions.push(client);
}
Expand Down
23 changes: 15 additions & 8 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { URI } from 'vscode-uri';
import {
DEPLOY_PLAYGROUND,
DEPLOY_PLAYGROUND_MESSAGE,
ERROR_MESSAGE,
TEST_FILE_REQUEST,
TestResult,
} from '../common/connectionTypes';
Expand Down Expand Up @@ -209,7 +210,6 @@ async function getPackageSources(
}

let loadingPackages = false;
let packageConfigError = false;
let packageConfigChangeTimeout: ReturnType<typeof setTimeout>;
function notifyPackageConfigChange(reuseCached = false) {
if (!reuseCached) {
Expand All @@ -218,7 +218,6 @@ function notifyPackageConfigChange(reuseCached = false) {
loadingPackages = true;
clearTimeout(packageConfigChangeTimeout);
packageConfigChangeTimeout = setTimeout(async () => {
packageConfigError = false;
try {
resetContexts();

Expand Down Expand Up @@ -278,16 +277,23 @@ function notifyPackageConfigChange(reuseCached = false) {
context.motoko.usePackage(name, path);
});
} catch (err) {
packageConfigError = true;
connection.sendNotification(ERROR_MESSAGE, {
message: `Error while resolving Motoko packages:`,
detail: String(err).replace(/^Error: /, ''),
});
context.error = String(err);
console.warn(err);
return;
}
} catch (err) {
packageConfigError = true;
} catch (err: any) {
connection.sendNotification(ERROR_MESSAGE, {
message: `Error while loading Motoko packages:`,
detail: String(err).replace(/^Error: /, ''),
});
console.error(
`Error while reading packages for directory (${dir}): ${err}`,
);
return;
}
}),
);
Expand All @@ -303,10 +309,11 @@ function notifyPackageConfigChange(reuseCached = false) {
loadingPackages = false;
notifyWorkspace(); // Update virtual file system
notifyDfxChange(); // Reload dfx.json
} catch (err) {
} catch (err: any) {
loadingPackages = false;
packageConfigError = true;
console.error(`Error while loading packages: ${err}`);
console.error(
`Error while loading packages: ${err?.message || err}`,
);
}
}, 1000);
}
Expand Down

0 comments on commit dfb5480

Please sign in to comment.