fix: handle non-string values in jsonToEnv and fix file extension#10
Conversation
- fix jsonToEnv to safely convert non-string values to strings - update type signature from Record<string, string> to Record<string, unknown> - add String() conversion for numbers, booleans, objects, null, and undefined - fix help message to show .e2smrc.jsonc instead of .e2smrc.json - add comprehensive tests for non-string value conversion
|
There was a problem hiding this comment.
Pull request overview
This PR fixes runtime errors and improves documentation consistency by addressing issues in the jsonToEnv function and help text. The changes prevent errors when AWS Secrets Manager returns non-string values and correct a file extension reference.
Changes:
- Modified
jsonToEnvto handle non-string values (numbers, booleans, null, undefined, objects) by converting them to strings - Updated type signature from
Record<string, string>toRecord<string, unknown>to reflect the broader input support - Fixed help message to reference
.e2smrc.jsoncinstead of.e2smrc.jsonfor consistency
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/lib/env.ts | Updated jsonToEnv function to safely convert non-string values to strings before processing |
| src/lib/env.test.ts | Added comprehensive tests for number, boolean, null, undefined, and object value conversions |
| src/index.ts | Corrected help message to reference .e2smrc.jsonc file extension |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- use JSON.stringify for objects and arrays instead of String() - preserve data structure in .env output for complex types - add test case for array value conversion
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Issue
N/A - Fix runtime errors and documentation consistency issues identified in code review
Changes
jsonToEnvfunction to safely handle non-string values from AWS Secrets ManagerRecord<string, string>toRecord<string, unknown>String()conversion for numbers, booleans, objects, null, and undefined values.e2smrc.jsoncinstead of.e2smrc.jsonVerification
Additional Notes
This PR addresses code review feedback to improve robustness when handling secrets that may have been created or modified outside this tool. The
jsonToEnvfunction now gracefully converts any JSON value type to a string representation, preventing runtime errors when.replace()is called on non-string values.The help message fix ensures consistency with the actual file extension used throughout the codebase and documentation.