You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Prevent API calls during discovery and correct arg parsing
- Python Library (`ObsidianPluginDevPythonToJS.py`):
- Fixed `NameError: name 'args' is not defined` in `_handle_cli_args`
by adding `args, unknown = parser.parse_known_args()`.
- Ensured `_script_settings_definitions` defaults to an empty list
if not defined by the user script before `_handle_cli_args` is called.
- Introduced `OBSIDIAN_BRIDGE_MODE` environment variable handling:
- Plugin sets `OBSIDIAN_BRIDGE_MODE="discovery"` when running scripts
for settings discovery.
- Library `__init__` reads this mode.
- `_send_receive` now checks `self._execution_mode`. If "discovery",
it raises an `ObsidianCommError` immediately, preventing API calls
and providing a clear error message. This effectively sandboxes
library API usage during discovery for scripts not properly handling
`--get-settings-json`.
- TypeScript Plugin (`src/python_executor.ts`):
- Added `OBSIDIAN_BRIDGE_MODE: "discovery"` to the environment variables
when spawning scripts for settings discovery.
This resolves issues where scripts not handling `--get-settings-json`
could execute unintended API calls during the plugin's startup/settings
refresh phase. It also fixes a bug in the Python library's CLI argument
handling. Auto-start logic appears to be functioning correctly with
existing settings checks.
plugin.logDebug(`Executing discovery with PYTHONPATH: ${discoveryPYTHONPATH} and cwd: ${scriptDir}`);
87
91
constpythonProcess=spawn(plugin.pythonExecutable!,args,{timeout: discoveryTimeoutMs,cwd: scriptDir,env: env});// Set working directory to the script's folder // Pass modified environment
@@ -340,40 +344,80 @@ export async function runAllPythonScripts(plugin: ObsidianPythonBridge): Promise
340
344
* Called after plugin load, server start, and initial settings sync.
341
345
* @param plugin The ObsidianPythonBridge plugin instance.
runPythonScript(plugin,absolutePath,"auto-start");// No await needed here
393
+
}else{
394
+
plugin.logWarn(`Skipping delayed auto-start for ${relativePath}: Script status changed during delay (Active: ${latestActivationStatus}, AutoStart: ${latestAutoStartStatus}).`);
395
+
}
396
+
},delayMs);
397
+
}else{
398
+
// Immediate execution (no need to re-check here as we just loaded settings)
399
+
runPythonScript(plugin,absolutePath,"auto-start");// No await needed here
400
+
}
401
+
scriptsRunCount++;
402
+
}else{
403
+
plugin.logWarn(`Skipping auto-start for ${relativePath}: Script file not found at ${absolutePath}.`);
404
+
}
405
+
}catch(error){
406
+
plugin.logError(`Error checking file status for auto-start script ${absolutePath}:`,error);
371
407
}
372
-
}catch(error){plugin.logError(`Error checking file status for auto-start script ${absolutePath}:`,error);}
408
+
}else{
409
+
plugin.logDebug(`Skipping auto-start for ${relativePath}: Script is not active.`);
410
+
}
411
+
}else{
412
+
plugin.logDebug(`Skipping auto-start for ${relativePath}: Auto-start setting is false.`);
0 commit comments