Always validate configuration values before use, provide sensible defaults, and centralize constants in shared modules. When implementing configuration handling:
Always validate configuration values before use, provide sensible defaults, and centralize constants in shared modules. When implementing configuration handling:
// Correct: Properly handles zero values if (configuration.commandExecutionTimeout !== undefined) { // Handle timeout }
2. Apply bounds checking for numerical values to ensure they're within acceptable ranges:
```typescript
// Validate within reasonable bounds
const maxImagesPerResponse = Math.max(1, Math.min(100, state?.mcpMaxImagesPerResponse ?? 20));
const maxImageSizeMB = Math.max(0.1, Math.min(50, state?.mcpMaxImageSizeMB ?? 10));
// Ensure configuration value is a valid number
this.modelDimension = typeof config.modelDimension === 'number' && !isNaN(config.modelDimension)
? config.modelDimension
: DEFAULT_MODEL_DIMENSION;
// Use the constant throughout the codebase return settings.claudeCodeMaxOutputTokens || DEFAULT_CLAUDE_CODE_MAX_OUTPUT_TOKENS; ```
Proper configuration handling prevents subtle bugs, improves maintainability, and makes your code more resilient to external changes.
Enter the URL of a public GitHub repository