概述
错误消息改进工作流是一个初级难度的工作流。审计并改进代码库中的错误消息,使其可操作、清晰、有助于调试。该工作流的目标是:Improve error messages throughout the codebase to reduce support tickets and speed up debugging.
环境准备
执行本工作流需要以下环境:A codebase with error handling code;A search tool (grep, ripgrep);Error message style guide or guidelines。请确保在开始前准备好所有必需的工具和资源,以避免中途因环境问题中断。
执行步骤
本工作流包含4个步骤。步骤1:Audit messages——Search the codebase for throw, raise, and error creation to find all error messages. 步骤2:Identify weak messages——Flag messages that are vague, lack context, or do not suggest a fix. 步骤3:Rewrite messages——Rewrite each weak message to include what went wrong, why, and how to fix it. 步骤4:Test error paths——Trigger each improved error path to verify the new message is displayed correctly.
验证与清理
预期结果:All error messages in the codebase are clear, actionable, and helpful for debugging.。验证方法:Trigger each error path and confirm the improved message is displayed and contains actionable guidance.。清理操作:No cleanup needed; improved messages should be committed.。estimatedMinutes 为 40 分钟。
代码示例
throw new Error(`Invalid config: missing "database.host". Check your .env file and ensure DATABASE_HOST is set.`);