Skip to content

Commit 4faa0bf

Browse files
committed
Stricter checks for invalid and duplicate indices, closes #13
1 parent 1503724 commit 4faa0bf

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

msg2po/core.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -846,14 +846,11 @@ def __init__(self, filepath: str, is_source: False, encoding=CONFIG.encoding):
846846
print(f"\t\tentry: {entry}")
847847
raise ValueError("Invalid translation character")
848848

849-
# skip invalid '000' entries in MSG files
850-
if fext == "msg" and index == "000":
851-
print(
852-
"WARN: {} - invalid entry number found, skipping:\n {{000}}{{}}{{{}}}".format(
853-
filepath, entry.value
854-
)
855-
)
856-
continue
849+
# fail on invalid '000' entries in MSG files
850+
if index == "000":
851+
print(f"ERROR: {filepath} - invalid entry index '000' found, aborting.")
852+
print(f"\t\tentry: {entry}")
853+
raise ValueError("Invalid entry index")
857854

858855
entry.index = line[self.fformat["index"]]
859856

@@ -904,13 +901,9 @@ def __init__(self, filepath: str, is_source: False, encoding=CONFIG.encoding):
904901

905902
# protection against duplicate indexes, part 2
906903
if entry.index in seen:
907-
print(
908-
"WARN: duplicate string definition found {}:{}, using new value:\n {}".format(
909-
filepath, entry.index, entry.value
910-
)
911-
)
912-
self.entries = [entry if x.index == entry.index else x for x in self.entries]
913-
continue
904+
print(f"ERROR: {filepath} - duplicate string index found: '{entry.index}'. Aborting.")
905+
print(f"\tLast value: {entry.value}")
906+
raise ValueError("Duplicate entry indices")
914907
else:
915908
seen.append(index)
916909

0 commit comments

Comments
 (0)