Skip to content

Commit bc483c7

Browse files
committed
fix(traces): correct line number in load_traces() error messages (0.3.2)
load_traces() used len(records)+1 as the error line number, which excluded blank lines and reported a lower-than-actual position. Fixed with enumerate(f, start=1) so the message always points at the real file line. Closes #57.
1 parent 5585b56 commit bc483c7

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎src/tracer/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __getattr__(name: str):
7878
return obj
7979

8080

81-
__version__ = "0.3.1"
81+
__version__ = "0.3.2"
8282

8383
__all__ = [
8484
# Core API

‎src/tracer/cloud/client.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CloudError(RuntimeError):
3939

4040
# A real User-Agent: the default "Python-urllib/x" trips Cloudflare's bot
4141
# protection on app.tracerml.ai (HTTP 403, CF error 1010).
42-
USER_AGENT = "tracer-cli/0.3.1 (+https://tracerml.ai)"
42+
USER_AGENT = "tracer-cli/0.3.2 (+https://tracerml.ai)"
4343

4444

4545
def _http(

‎src/tracer/traces/loader.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def load_traces(path: Union[str, Path]) -> TraceDataset:
2525
path = Path(path)
2626
records = []
2727
with path.open("r", encoding="utf-8") as f:
28-
for line in f:
28+
for lineno, line in enumerate(f, start=1):
2929
line = line.strip()
3030
if not line:
3131
continue
3232
try:
3333
row = json.loads(line)
3434
except json.JSONDecodeError as exc:
3535
raise ValueError(
36-
f"Malformed JSON in {path} at line {len(records) + 1}: {exc}"
36+
f"Malformed JSON in {path} at line {lineno}: {exc}"
3737
) from exc
3838
# Accept common key aliases so middleware dumps load without
3939
# reshaping (mirrors the scan loader). Canonical keys are
@@ -42,7 +42,7 @@ def load_traces(path: Union[str, Path]) -> TraceDataset:
4242
label_key = next((k for k in _LABEL_KEYS if k in row), None)
4343
if input_key is None or label_key is None:
4444
raise ValueError(
45-
f"Trace at line {len(records) + 1} is missing an input and/or "
45+
f"Trace at line {lineno} is missing an input and/or "
4646
f"teacher field. Accepted input keys: {_INPUT_KEYS}; "
4747
f"teacher keys: {_LABEL_KEYS}. Got keys: {list(row.keys())}"
4848
)

0 commit comments

Comments
 (0)