Prompt
Always wrap potentially unsafe operations (like JSON parsing, Buffer operations, or API calls) in try-catch blocks with appropriate error handling. Ensure error messages are user-friendly and actionable.
Example:
// Bad: Unsafe operation without error handling
const data = Buffer.from(input, "base64").toString("utf8");
const config = JSON.parse(toolCall.function.arguments);
// Good: Proper error handling with user-friendly messages
try {
const data = Buffer.from(input, "base64").toString("utf8");
return data;
} catch (error) {
throw new Error("Invalid data format provided. Please check your input.");
}
try {
const config = JSON.parse(toolCall.function.arguments);
return config;
} catch (error) {
throw new Error("Invalid configuration format. Please verify the syntax.");
}
Key points:
- Identify potentially unsafe operations in your code
- Always wrap them in try-catch blocks
- Handle errors gracefully with appropriate recovery or fallback logic
- Provide clear, user-friendly error messages that help users understand and resolve the issue
- Avoid exposing technical details in user-facing error messages unless necessary