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.
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:
Enter the URL of a public GitHub repository