From bf417172b8478a6130bc3cfc96dbe4e633aa504a Mon Sep 17 00:00:00 2001 From: Mark Ayers Date: Sun, 12 Oct 2025 19:52:04 -0400 Subject: [PATCH] Add comprehensive settings validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/main.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 33194f3..3d954de 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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; }