Skip to content

Commit fc03a2f

Browse files
committed
refactor(obsidian-dataview): check that the API is non-null before resolving
1 parent 4104371 commit fc03a2f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/lib/obsidian-dataview/adapter.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ import { mergeTaskParts } from "@/data/merge-task-parts";
55
import { parseTaskEmojis } from "@/data/parse-task-emojis";
66

77
export class Dataview {
8-
private constructor(
9-
private readonly plugin: Plugin,
10-
private readonly dv: DataviewApi = getAPI(plugin.app),
11-
) {}
8+
private constructor(private readonly plugin: Plugin, private readonly dv: DataviewApi) {}
129

1310
/** IMPORTANT: Must be called from within `onLayoutReady` callback, otherwise the plugin will freeze! */
1411
public static async getReady(plugin: Plugin): Promise<Dataview> {
1512
return new Promise<Dataview>((resolve, reject) => {
1613
if (!isPluginEnabled(plugin.app)) {
1714
reject(new Error("obsidian-dataview is not installed and/or enabled"));
1815
} else {
19-
const api: DataviewApi = getAPI(plugin.app);
20-
if (api?.index.initialized) {
16+
const api = getAPI(plugin.app);
17+
if (!api) {
18+
reject(new Error("obsidian-dataview could not be loaded"));
19+
} else if (api.index.initialized) {
2120
resolve(new Dataview(plugin, api));
2221
} else {
2322
plugin.registerEvent(

0 commit comments

Comments
 (0)