Skip to content

Commit 5f5c127

Browse files
ritwik-gclaude
andcommitted
Fix validation output to show environment names in errors
- Fixed Rich markup issue by escaping square brackets in error output - Added test to ensure multi-environment validation shows which env has issues - Now errors clearly indicate [env] prefix for better debugging 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2389c7b commit 5f5c127

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

helm_values_manager/validator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, context: str, message: str, env: Optional[str] = None):
3434

3535
def __str__(self):
3636
if self.env:
37-
return f"[{self.env}] {self.context}: {self.message}"
37+
return f"\\[{self.env}] {self.context}: {self.message}"
3838
return f"{self.context}: {self.message}"
3939

4040

@@ -192,6 +192,7 @@ def _validate_all_values(self):
192192
for values_file in self.values_base_path.glob(pattern):
193193
# Extract environment from filename
194194
env = values_file.stem.replace("values-", "")
195+
# Debug: print(f"Validating environment: {env}")
195196
self._validate_values_for_env(env)
196197

197198
def _validate_value_type(self, value: Any, expected_type: str) -> bool:
@@ -233,7 +234,8 @@ def print_errors(self):
233234

234235
console.print(ErrorMessage("Validation failed:"))
235236
for error in self.errors:
236-
console.print(f" - {error}")
237+
# Debug: print(f"DEBUG: error.env={error.env}, error={error}")
238+
console.print(f" - {str(error)}")
237239

238240

239241
def validate_command(

tests/test_validate.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,56 @@ def test_validate_unknown_key_in_values(tmp_path):
342342
"--env", "dev"
343343
])
344344
assert result.exit_code == 1
345-
assert "Unknown key: unknown-key" in result.stdout
345+
assert "Unknown key: unknown-key" in result.stdout
346+
347+
348+
def test_validate_multi_env_shows_environment_names(tmp_path):
349+
"""Test that validation errors show which environment has issues."""
350+
# Create schema
351+
schema_file = tmp_path / "schema.json"
352+
schema_data = {
353+
"version": "1.0",
354+
"values": [
355+
{
356+
"key": "database-host",
357+
"path": "db.host",
358+
"description": "Database hostname",
359+
"type": "string",
360+
"required": True
361+
}
362+
]
363+
}
364+
schema_file.write_text(json.dumps(schema_data, indent=2))
365+
366+
# Create values for multiple environments with different errors
367+
values_dev = tmp_path / "values-dev.json"
368+
values_dev.write_text(json.dumps({
369+
"dev": {} # Missing required value
370+
}))
371+
372+
values_staging = tmp_path / "values-staging.json"
373+
values_staging.write_text(json.dumps({
374+
"staging": {
375+
"database-host": 123 # Wrong type
376+
}
377+
}))
378+
379+
values_prod = tmp_path / "values-prod.json"
380+
values_prod.write_text(json.dumps({
381+
"prod": {
382+
"database-host": "prod-db.example.com" # Correct
383+
}
384+
}))
385+
386+
# Validate all environments
387+
result = runner.invoke(app, [
388+
"validate",
389+
"--schema", str(schema_file),
390+
"--values", str(tmp_path)
391+
])
392+
393+
assert result.exit_code == 1
394+
assert "[dev] Values: Missing required value: database-host" in result.stdout
395+
assert "[staging] Values: Type mismatch for database-host: expected string" in result.stdout
396+
# prod should not appear in errors since it's correct
397+
assert "[prod]" not in result.stdout

0 commit comments

Comments
 (0)