-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
more cleanup #9
base: main
Are you sure you want to change the base?
more cleanup #9
Conversation
Reviewer's Guide by SourceryThis PR focuses on improving environment variable handling and code organization. It replaces the 'dotenv' package with 'dotenvx' for environment variable management, enhances error reporting for environment variable validation, and updates import paths for better modularity. File-Level Changes
Tips
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @hassancodess - I've reviewed your changes - here's some feedback:
Overall Comments:
- Can you provide more context on why the switch from dotenv to dotenvx was made? Are there specific features or benefits we're aiming to leverage?
- The DATABASE_URL has been removed from the config schema. Was this intentional, or should it be kept?
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
} | ||
} | ||
}); | ||
}; | ||
|
||
// Remove .optional() from requried schema properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick (typo): Update or remove the outdated comment
This comment contains a typo ('requried') and doesn't seem to reflect the actual changes made. Consider updating it to accurately describe the current schema or remove it if it's no longer relevant.
dotenv.config(); | ||
dotenvx.config(); | ||
|
||
const prettyPrintErrors = (errObj: ZodError) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider simplifying error handling by using Zod's built-in error formatting.
While the intention to provide more detailed error information is good, the current implementation adds unnecessary complexity. Consider simplifying the error handling by leveraging Zod's built-in error formatting capabilities. Here's a suggested approach:
import dotenvx from '@dotenvx/dotenvx';
import { z } from 'zod';
dotenvx.config();
const configSchema = z.object({
// ... (keep the existing schema definition)
});
export type Config = z.infer<typeof configSchema>;
const config = configSchema.safeParse(process.env);
if (!config.success) {
console.error('Error in environment variables:');
console.error(config.error.format());
process.exit(1);
}
export default config.data;
This approach:
- Uses Zod's built-in
format()
method to display errors, eliminating the need for a customprettyPrintErrors
function. - Simplifies the error logging while still providing detailed information about which environment variables are incorrect.
- Maintains the improved debugging capabilities with less code.
This change reduces complexity while keeping the functionality intact, making the code more maintainable and easier to understand.
This PR includes the following updates:
Summary by Sourcery
Enhance environment variable management by replacing dotenv with dotenvx and improve error formatting for validation errors. Update import paths in the upload controller for better module organization.
Enhancements: