Skip to content

Commit

Permalink
* If there's an error during installation, don't make the version as …
Browse files Browse the repository at this point in the history
…updated.

* throw during createModel if it fails
  • Loading branch information
jasonwilliams committed Aug 20, 2021
1 parent ca1b411 commit f6b301f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to the "anki" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [1.2.3]

- Throw an error if the template is not installed correctly, allowing the user to try again.

## [1.2.1]

- Added more diagnostics and logging surrounding the bug of missing note types
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "anki",
"displayName": "Anki for VSCode",
"description": "Sync notes with your locally running Anki",
"version": "1.2.2",
"version": "1.2.3",
"publisher": "jasew",
"engines": {
"vscode": "^1.47.0"
Expand Down
2 changes: 1 addition & 1 deletion src/AnkiCardProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class AnkiCardProvider implements TreeDataProvider<Dependency> {
try {
decks = await this.ankiService.deckNamesAndIds();
} catch (e) {
window.showErrorMessage("Failed to get any Anki Decks");
window.showErrorMessage("Failed to get any Decks. Is Anki running?");
return;
}

Expand Down
28 changes: 12 additions & 16 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import {
window,
extensions,
ExtensionContext,
workspace,
Disposable,
} from "vscode";
import { AnkiService } from "./AnkiService";
import { AnkiCardProvider } from "./AnkiCardProvider";
import {
getExtensionLogger,
IVSCodeExtLogger,
LogLevel,
LogLevel
} from "@vscode-logging/logger";
import { initLogger, getLogger } from "./logger";
import { registerCommands } from "./commands";
import semver from "semver";
import { subscriptions } from "./subscriptions";
import {
ExtensionContext, extensions, window, workspace
} from "vscode";
import { AnkiCardProvider } from "./AnkiCardProvider";
import { AnkiService } from "./AnkiService";
import { registerCommands } from "./commands";
import { AnkiFS, initFilesystem } from "./fileSystemProvider";
import { initState, getAnkiState } from "./state";
import { initialSetup } from "./initialSetup";
import { isTemplateInstalled, updateTemplate } from "./manageTemplate";
import { getLogger, initLogger } from "./logger";
import { createOrUpdateTemplate, isTemplateInstalled } from "./manageTemplate";
import { getAnkiState, initState } from "./state";
import { subscriptions } from "./subscriptions";

require("./resources/vscodeAnkiPlugin.scss");

Expand Down Expand Up @@ -95,7 +91,7 @@ export async function activate(context: ExtensionContext) {
templateInstalled = await isTemplateInstalled(extContext);
getLogger().info(`Status of note type on Anki: ${templateInstalled}`);
if (!templateInstalled) {
await updateTemplate(extContext);
await createOrUpdateTemplate(extContext);
}
} else {
getLogger().info('Could not connect to Anki');
Expand Down
6 changes: 4 additions & 2 deletions src/initialSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ export async function initialSetup(ctx: IContext) {
await createOrUpdateTemplate(ctx);
result = await ctx.ankiService.storeMultipleFiles(resources);
disposable.dispose();
} catch (e) {
} catch (e: any) {
window.showErrorMessage(
"Anki Installation: Unable to update resources on Anki"
"Anki Installation: Unable to update resources on Anki, please make sure Anki is running and try again"
);
ctx.logger.error(e);
// If any of the above failed we don't want to update the version, meaning it will try again next time the extension has started
return;
}

// If assets are safely installed we can set a flag so we don't need to do this action again
Expand Down
8 changes: 7 additions & 1 deletion src/manageTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ export async function createOrUpdateTemplate(ctx: IContext) {
getLogger().info(
`${CONSTANTS.defaultTemplateName} was not found in Anki. Will attempt to upload..`
);
let result;
try {
result = await ctx.ankiService.createModel(model);
} catch(e) {
getLogger().error(`Creating the template on Anki has failed: ${e}`);
throw new Error(`Failed to upload template! ${e}`);
}

const result = await ctx.ankiService.createModel(model);
if (result.error) {
getLogger().error(`Failed to upload template: ${result.error}`);
throw new Error("Failed to upload template!");
Expand Down

0 comments on commit f6b301f

Please sign in to comment.