When calltype ID lookup fails, continue skips to next label — but label and
label_metadata rows were already inserted. Creates labels without their
expected subtypes.
Fix: Check calltype resolution before inserting the label, or treat as
segment-level error.
2. Fragile JSON construction for label_metadata (line 710-716)
escapedComment := strings.ReplaceAll(label.Comment, `"`, `\"`)
Only escapes ". Backslashes, newlines, tabs are not handled — produces
invalid JSON if comment contains \.
Fix: Use json.Marshal to build the metadata map.
3. placeholders() duplicated
Defined in utils/mapping.go:262 and tools/import_ml_selections.go:1125.
import_segments.go uses it at line 330 — needs the tools/ package copy.
Consider moving to utils/ as the single source.
Minor Issues
4. Progress percentage inaccurate
totalFiles = len(scannedFiles) includes failed-validation files. Resolves
naturally when iterating fileIDMap instead.
5. file_metadata INSERT uses string concat in SQL (line 568)
json('{"skraak_hash": "' || ? || '"}')
Safe (hex-only hash), but the ON CONFLICT clause already uses json_set().
Could use json_set for both for consistency.
What's Good
- Thorough 4-phase validation before any DB writes
- Single transaction with rollback
- Event logging for audit trail
- Hash-based file matching (not filename)
- Fresh-import-only guard
- Bookmark skip logic
- Comprehensive error collection with stage tags
- Clean two-layer architecture
Files to Modify
1. tools/import_segments.go — critical bug + medium issues 1-2
Verification
go build -o skraak
# Run against test data with known .data files and mapping
# Verify segments/labels appear in DB with correct species/calltype IDs
╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌