Skip to content

Commit f8496cf

Browse files
committed
chore: limit displayed validation errors to 10 and update output formatting
1 parent 87d1315 commit f8496cf

2 files changed

Lines changed: 6 additions & 127 deletions

File tree

cli/cli.py

Lines changed: 4 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def _row_sort_key(row_value):
121121
except (TypeError, ValueError):
122122
return (1, str(row_value))
123123

124-
max_errors_to_show = 1000
124+
max_errors_to_show = 10
125125
shown = 0
126126
first_group = True
127127
for row in sorted(grouped_errors.keys(), key=_row_sort_key):
@@ -141,13 +141,13 @@ def _row_sort_key(row_value):
141141
bold=True,
142142
)
143143

144-
for err in row_errors:
144+
for idx, err in enumerate(row_errors, start=1):
145145
if shown >= max_errors_to_show:
146146
break
147147
field = err.get("field", "unknown")
148148
message = err.get("error") or err.get("msg") or "validation error"
149149
input_value = err.get("value")
150-
prefix_raw = " ! "
150+
prefix_raw = f" {idx}. "
151151
field_raw = f"{field}:"
152152
msg_chunks = wrap(
153153
str(message),
@@ -163,128 +163,7 @@ def _row_sort_key(row_value):
163163
for chunk in msg_chunks[1:]:
164164
typer.secho(f"{msg_indent}{chunk}", fg=typer.colors.BRIGHT_YELLOW)
165165
if input_value is not None:
166-
input_prefix = " input="
167-
input_chunks = wrap(
168-
str(input_value), width=max(20, 200 - len(input_prefix))
169-
) or [""]
170-
typer.secho(
171-
f"{input_prefix}{input_chunks[0]}", fg=typer.colors.BRIGHT_WHITE
172-
)
173-
input_indent = " " * len(input_prefix)
174-
for chunk in input_chunks[1:]:
175-
typer.secho(
176-
f"{input_indent}{chunk}", fg=typer.colors.BRIGHT_WHITE
177-
)
178-
shown += 1
179-
typer.echo()
180-
181-
if len(validation_errors) > shown:
182-
typer.secho(
183-
f"... and {len(validation_errors) - shown} more validation errors",
184-
fg=typer.colors.YELLOW,
185-
)
186-
187-
if detail:
188-
typer.secho("ERRORS", fg=typer.colors.BRIGHT_BLUE, bold=True)
189-
typer.secho(f"Error: {detail}", fg=typer.colors.BRIGHT_YELLOW, bold=True)
190-
191-
typer.secho("=" * 72, fg=typer.colors.BRIGHT_BLUE)
192-
193-
raise typer.Exit(result.exit_code)
194-
result = well_inventory_csv(file_path)
195-
payload = result.payload if isinstance(result.payload, dict) else {}
196-
summary = payload.get("summary", {})
197-
validation_errors = payload.get("validation_errors", [])
198-
detail = payload.get("detail")
199-
200-
if result.exit_code == 0:
201-
typer.secho("[WELL INVENTORY IMPORT] SUCCESS", fg=typer.colors.GREEN, bold=True)
202-
else:
203-
typer.secho(
204-
"[WELL INVENTORY IMPORT] COMPLETED WITH ISSUES",
205-
fg=typer.colors.BRIGHT_YELLOW,
206-
bold=True,
207-
)
208-
typer.secho("=" * 72, fg=typer.colors.BRIGHT_BLUE)
209-
210-
if summary:
211-
processed = summary.get("total_rows_processed", 0)
212-
imported = summary.get("total_rows_imported", 0)
213-
rows_with_issues = summary.get("validation_errors_or_warnings", 0)
214-
typer.secho("SUMMARY", fg=typer.colors.BRIGHT_BLUE, bold=True)
215-
typer.echo(
216-
f"Summary: processed={processed} imported={imported} rows_with_issues={rows_with_issues}"
217-
)
218-
typer.secho(f" processed : {processed}", fg=typer.colors.CYAN)
219-
typer.secho(f" imported : {imported}", fg=typer.colors.GREEN)
220-
issue_color = (
221-
typer.colors.BRIGHT_YELLOW if rows_with_issues else typer.colors.GREEN
222-
)
223-
typer.secho(f" rows_with_issues : {rows_with_issues}", fg=issue_color)
224-
225-
if validation_errors:
226-
typer.secho("VALIDATION", fg=typer.colors.BRIGHT_BLUE, bold=True)
227-
typer.secho(
228-
f"Validation errors: {len(validation_errors)}",
229-
fg=typer.colors.BRIGHT_YELLOW,
230-
bold=True,
231-
)
232-
grouped_errors = defaultdict(list)
233-
for err in validation_errors:
234-
row = err.get("row", "?")
235-
grouped_errors[row].append(err)
236-
237-
def _row_sort_key(row_value):
238-
try:
239-
return (0, int(row_value))
240-
except (TypeError, ValueError):
241-
return (1, str(row_value))
242-
243-
max_errors_to_show = 100
244-
shown = 0
245-
first_group = True
246-
for row in sorted(grouped_errors.keys(), key=_row_sort_key):
247-
if shown >= max_errors_to_show:
248-
break
249-
250-
row_errors = grouped_errors[row]
251-
if not first_group:
252-
typer.secho(
253-
" " + "-" * 56,
254-
fg=typer.colors.BRIGHT_BLACK,
255-
)
256-
first_group = False
257-
typer.secho(
258-
f" Row {row} ({len(row_errors)} issue{'s' if len(row_errors) != 1 else ''})",
259-
fg=typer.colors.CYAN,
260-
bold=True,
261-
)
262-
263-
for err in row_errors:
264-
if shown >= max_errors_to_show:
265-
break
266-
field = err.get("field", "unknown")
267-
message = err.get("error") or err.get("msg") or "validation error"
268-
input_value = err.get("value")
269-
prefix_raw = " ! "
270-
field_raw = f"{field}:"
271-
msg_chunks = wrap(
272-
str(message),
273-
width=max(20, 200 - len(prefix_raw) - len(field_raw) - 1),
274-
) or [""]
275-
prefix = typer.style(prefix_raw, fg=typer.colors.BRIGHT_YELLOW)
276-
field_part = typer.style(
277-
field_raw, fg=typer.colors.BRIGHT_YELLOW, bold=True
278-
)
279-
first_msg_part = typer.style(
280-
msg_chunks[0], fg=typer.colors.BRIGHT_YELLOW
281-
)
282-
typer.echo(f"{prefix}{field_part} {first_msg_part}")
283-
msg_indent = " " * (len(prefix_raw) + len(field_raw) + 1)
284-
for chunk in msg_chunks[1:]:
285-
typer.secho(f"{msg_indent}{chunk}", fg=typer.colors.BRIGHT_YELLOW)
286-
if input_value is not None:
287-
input_prefix = " input="
166+
input_prefix = " input="
288167
input_chunks = wrap(
289168
str(input_value), width=max(20, 200 - len(input_prefix))
290169
) or [""]

tests/test_cli_commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ def fake_well_inventory(_file_path):
138138
assert "Validation errors: 2" in result.output
139139
assert (
140140
"Row 1 (1 issue)" in result.output
141-
and "! contact_1_phone_1: Invalid phone" in result.output
141+
and "1. contact_1_phone_1: Invalid phone" in result.output
142142
) or "- row=1 field=contact_1_phone_1: Invalid phone" in result.output
143-
assert "input='555-INVALID'" in result.output
143+
assert "input=555-INVALID" in result.output
144144

145145

146146
def test_water_levels_bulk_upload_default_output(monkeypatch, tmp_path):

0 commit comments

Comments
 (0)