Add comprehensive settings validation

Expand validateSettings() to check all critical settings before
processing, not just the API key:

API Key validation:
- Check for empty or whitespace-only values
- Validate format (must start with 'sk-' for OpenAI keys)

Output folder validation:
- Check for empty or whitespace-only values
- Reject paths with invalid filesystem characters (<>:"|?*\x00-\x1f)

Model validation:
- Ensure model is in the list of valid options (gpt-4o-mini, gpt-4o)
- Catches manually edited or corrupted settings

This prevents cryptic errors later in execution by catching configuration
issues early with clear, actionable error messages for users.

Fixes H5 (Incomplete settings validation) from CODE_REVIEW.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Mark Ayers 2025-10-12 19:52:04 -04:00
parent 635b1c6421
commit bf417172b8

View file

@ -129,10 +129,38 @@ export default class AtomizerPlugin extends Plugin {
}
private validateSettings(): boolean {
if (!this.settings.apiKey) {
// Validate API key
if (!this.settings.apiKey || !this.settings.apiKey.trim()) {
new Notice("Please set your OpenAI API key in settings");
return false;
}
// Validate API key format (basic check for OpenAI key pattern)
if (!this.settings.apiKey.startsWith("sk-")) {
new Notice("Invalid OpenAI API key format. Keys should start with 'sk-'");
return false;
}
// Validate output folder
if (!this.settings.outputFolder || !this.settings.outputFolder.trim()) {
new Notice("Output folder path cannot be empty");
return false;
}
// Check for invalid characters in folder path
const invalidChars = /[<>:"|?*\x00-\x1f]/;
if (invalidChars.test(this.settings.outputFolder)) {
new Notice("Output folder path contains invalid characters");
return false;
}
// Validate model selection
const validModels = ["gpt-4o-mini", "gpt-4o"];
if (!validModels.includes(this.settings.model)) {
new Notice(`Invalid model selected: ${this.settings.model}. Please choose a valid model in settings.`);
return false;
}
return true;
}