Skip to content

Commit e2987a6

Browse files
committed
Defensive programming around obsidian cli failure
1 parent 7cbbbaf commit e2987a6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

apps/obsidian/obsidian.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import subprocess
2+
import re
23

34
from talon import Context, Module, actions, settings
45

@@ -246,7 +247,28 @@ def language():
246247

247248

248249
def obsidian_run_cli_command(command_id: str):
249-
subprocess.run(["obsidian", "command", f"id={command_id}"], timeout=1.0)
250+
try:
251+
subprocess.check_output(
252+
["obsidian", "command", f"id={command_id}"], timeout=1.0
253+
)
254+
except OSError as e:
255+
print(f"Error running obsidian command via cli: {e}")
256+
print("Obsidian might not be on PATH?")
257+
except subprocess.CalledProcessError as e:
258+
# Note: As of at least obsidian version 1.12, the CLI never emits a failure exit code, so none of these will trigger currently, but a future update to obsidian might fix that.
259+
print(f"Error running obsidian command via cli: {e.output}")
260+
if "Command line interface is not enabled" in e.output:
261+
print(
262+
"Talon settings say to use the obsidian CLI for obsidian commands, but CLI interface control is disabled in obsidian settings."
263+
)
264+
print("Please turn it on in Settings > General >Advanced")
265+
elif re.match('Command "[^"]*"not found', e.output):
266+
print(
267+
f"Command '{command_id}' does not seem to be a valid obsidian command"
268+
)
269+
270+
print(f"Falling back to palette command for {command_id}")
271+
obsidian_palette_command(command_id)
250272

251273

252274
def command_uri_or_client_fallback(command_id: str):

0 commit comments

Comments
 (0)