environment-validation
Validate configuration early to fail fast. Apply when writing setup scripts, Lambda cold starts, or any initialization code that depends on environment variables.
How do I install this agent skill?
npx skills add https://github.com/loxosceles-dev/dev-skills --skill environment-validationIs this agent skill safe to install?
- Gen Agent Trust Hubpass
This skill provides documentation and code patterns for a design pattern focused on early validation of environment variables. It contains no executable code or malicious instructions.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
What does this agent skill do?
Environment Validation Pattern
This is a reference pattern. Learn from the approach, adapt to your context — don't copy verbatim.
Problem: Scripts fail halfway through due to missing environment variables, wasting time and leaving systems in inconsistent states.
Solution: Validate all required environment variables at the start, before any operations begin.
Pattern
Validate Early: Check all required configuration before starting business logic.
// ✅ Preferred: Validate at entry point
function validateEnvironment() {
const required = ['AWS_REGION', 'PROJECT_ID', 'ENVIRONMENT'];
const missing = required.filter(key => !process.env[key]);
if (missing.length > 0) {
throw new Error(`Missing required environment variables: ${missing.join(', ')}`);
}
}
// At script/app entry point
validateEnvironment();
// Now proceed with business logic
Environment Manager Pattern (for complex projects):
// shared/env-loader.ts
export function loadAndValidateEnv() {
const required = ['AWS_REGION', 'PROJECT_ID', 'ENVIRONMENT'];
const missing = required.filter(key => !process.env[key]);
if (missing.length > 0) {
throw new Error(`Missing: ${missing.join(', ')}`);
}
return {
awsRegion: process.env.AWS_REGION!,
projectId: process.env.PROJECT_ID!,
environment: process.env.ENVIRONMENT!
};
}
// Usage in scripts/handlers
const config = loadAndValidateEnv();
// All env vars validated, proceed with business logic
Benefits
- Fail Fast: Catch configuration errors immediately
- Clear Errors: Know exactly what's missing
- Clean Code: Business logic not cluttered with validation
- Consistent: Single validation point for entire application
When to Use
- Always: For deployment scripts, Lambda handlers, CLI tools
- Entry Points: Validate at application/script start
- Shared Config: Use environment manager for complex projects
Integration with CLI Architecture
The 3-Tier CLI Architecture includes an EnvironmentManager that implements this pattern:
// core/env-manager.ts
export class EnvironmentManager extends BaseManager {
loadEnv(stage: string): Record<string, string> {
this.log(`Loading environment for ${stage}`);
// Validate required variables
const required = ['AWS_REGION', 'PROJECT_ID'];
const missing = required.filter(key => !process.env[key]);
if (missing.length > 0) {
throw new Error(`Missing: ${missing.join(', ')}`);
}
return process.env;
}
}
This ensures all CLI commands validate environment before executing business logic.
Related
- CLI Architecture - 3-Tier pattern includes EnvironmentManager
- Configuration Management
- Error Handling
- Security Baseline
Progressive Improvement
If the developer corrects a behavior that this skill should have prevented, suggest a specific amendment to this skill to prevent the same correction in the future.
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/loxosceles-dev/dev-skills/environment-validation">View environment-validation on skillZs</a>