Diagnose and fix common Obsidian plugin errors and exceptions.
Use when encountering plugin errors, debugging failed operations,
or troubleshooting Obsidian plugin issues.
Trigger with phrases like "obsidian error", "fix obsidian plugin",
"obsidian not working", "debug obsidian plugin".
Common gotcha: the file must be styles.css (plural), not style.css.
Step 4: Commands Not Showing in Palette
Commands registered outside onload() or after the plugin is enabled won't appear in the command palette.
// BROKEN: adding command in a separate method called conditionally
async onload() {
await this.loadSettings();
// command never added because registerCommands is not called
}
registerCommands() {
this.addCommand({ id: 'test', name: 'Test', callback: () => {} });
}
// FIXED: add all commands directly in onload
async onload() {
await this.loadSettings();
this.addCommand({
id: 'test',
name: 'Test',
callback: () => {
new Notice('Working!');
}
});
}
If a command should only be available when a markdown file is open, use editorCallback instead of callback — Obsidian automatically hides it when no editor is active:
Load settings with defaults to prevent undefined fields after plugin updates:
async loadSettings() {
// loadData() returns null on first run — Object.assign handles this safely
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
Object.assign merges saved data over defaults, so new fields added in later versions get their default value instead of undefined.
Output
Identified error matched to one of the six categories
Root cause explanation
Working code fix applied to plugin source
Error Handling
Error
Cause
Solution
TypeError: Cannot read properties of null
Workspace not ready
Use onLayoutReady or null-check
Plugin failed to load
Build error or bad manifest
Check console, verify manifest.json fields
CSS has no effect
Wrong filename or path
Must be styles.css in plugin root
Command missing from palette
Not added in onload()
Move addCommand into onload
Error: ENOENT on vault read
File doesn't exist
Check with adapter.exists() first
Settings reset on restart
Missing saveData call
Call saveData after every mutation
Examples
Quick Diagnostic Checklist
When a plugin fails to load, check these in order:
Open Developer Console (Ctrl/Cmd+Shift+I) and look for red errors
Verify main.js, manifest.json, and styles.css exist in plugin folder
Confirm manifest.json has id, name, version, minAppVersion
Confirm main.ts uses export default class
Rebuild with npm run build and reload Obsidian (Ctrl/Cmd+R)
Debug Logging Pattern
// Add to your plugin class for temporary debugging
private debug(msg: string, ...args: any[]) {
if (this.settings.debugMode) {
console.log(`[${this.manifest.id}] ${msg}`, ...args);
}
}