Skip to content

Commit 5c562bc

Browse files
hive-botclaude
andcommitted
fix: raise a ValueError for a glossary CSV row without a target
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 61d9d2d commit 5c562bc

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
249249
the `glossary` parameter. Calling it emits a `DeprecationWarning`.
250250

251251
### Fixed
252+
- A glossary CSV row without a target term now raises a `ValueError` naming
253+
the row; previously a bare `IndexError` (it is still an `IndexError`).
252254
- A connection that is reset or breaks off while the response body is read
253255
is now retried like other connection failures, and raises
254256
`ConnectionException` with `should_retry` `True` once retries are used up.

‎deepl/util.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ def convert_dict_to_tsv(
183183
)
184184

185185

186+
class _GlossaryCsvRowError(ValueError, IndexError):
187+
"""ValueError for an invalid CSV row; also an IndexError, which earlier
188+
versions raised."""
189+
190+
186191
def convert_csv_to_dict(
187192
csv_data: Union[TextIO, BinaryIO, str, bytes, Any],
188193
skip_checks: bool = False,
@@ -216,6 +221,8 @@ def convert_csv_to_dict(
216221
for line, index in zip(reader, itertools.count(1)):
217222
if not line:
218223
continue
224+
if len(line) < 2:
225+
raise _GlossaryCsvRowError(f"Entry {index} has no target term")
219226
source, target = line[0].strip(), line[1].strip()
220227
if source in entries_dict:
221228
raise ValueError(

‎tests/offline/test_util.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ def test_convert_dict_to_tsv():
3838
deepl.convert_dict_to_tsv({"\t": "target"})
3939

4040

41+
def test_glossary_csv_row_without_target_raises_value_error():
42+
with pytest.raises(ValueError, match="Entry 1 has no target term") as e:
43+
deepl.util.convert_csv_to_dict("hello\n")
44+
assert isinstance(e.value, IndexError)
45+
46+
4147
def test_parse_timestamp_microseconds():
4248
"""Standard 6-digit fractional seconds should parse correctly."""
4349
result = parse_timestamp("2025-01-15T10:30:00.123456+0000")

0 commit comments

Comments
 (0)