Automatically improve Error messages across your entire codebase using Droid Exec
This tutorial demonstrates how to use Droid Exec to refactor error messages across hundreds of files simultaneously. The script intelligently finds all ResponseError instantiations and improves their messages to be more descriptive, actionable, and user-friendly.
ResponseError is Factory’s internal error handling class used to throw HTTP-style errors with specific status codes. These error classes are used throughout the codebase to handle API errors.
Once you’re ready, run the actual error message improvement:
Copy
Ask AI
# Actually improve the error messages (default behavior)./droid-improve-errors.sh apps/factory-admin# Or explicitly set DRY_RUN=falseDRY_RUN=false ./droid-improve-errors.sh apps/factory-admin# Adjust concurrency for faster processingCONCURRENCY=10 ./droid-improve-errors.sh packages
Actual execution example:
Copy
Ask AI
% ./scripts/droid-improve-errors.sh apps/factory-admin/src/app/api/_utils/middleware.ts=== Droid Error Message Improvement ===Directory: apps/factory-admin/src/app/api/_utils/middleware.tsConcurrency: 5Found 1 files with ResponseError classesProcessing: apps/factory-admin/src/app/api/_utils/middleware.ts Found 6 error instantiation(s)## SummaryI've successfully improved all error messages in the `apps/factory-admin/src/app/api/_utils/middleware.ts` file. The improvements include making the messages more descriptive, actionable, and user-friendly while providing helpful context and suggestions for resolution. All 7 error instantiations were updated, and the TypeScript compilation verified that the changes are syntactically correct.
// middleware.tsif (!sessionCookie?.value) { throw new ResponseError401Unauthorized('No session');}if (!userRecord) { throw new ResponseError401Unauthorized('Invalid session');}
Copy
Ask AI
// middleware.tsif (!sessionCookie?.value) { throw new ResponseError401Unauthorized( 'Session cookie not found. Please sign in again to access the admin dashboard.' );}if (!userRecord) { throw new ResponseError401Unauthorized( 'Session is invalid or has expired. Please sign in again to continue.' );}
Clear instructions on what went wrong and how to fix it
// middleware.tsif (!authHeader) { throw new ResponseError401Unauthorized('Missing auth header');}if (authHeader !== `Bearer ${secret}`) { throw new ResponseError401Unauthorized('Invalid token');}
Copy
Ask AI
// middleware.tsif (!authHeader) { throw new ResponseError401Unauthorized( 'Authorization header is missing. Please include a valid Bearer token in the Authorization header.' );}if (authHeader !== `Bearer ${secret}`) { throw new ResponseError401Unauthorized( 'Invalid or expired authorization token. Please verify your API credentials and ensure the token is properly formatted as "Bearer <token>".' );}
Specific format requirements and troubleshooting hints added