Skip to content

Fix Auto Parse TypeError from invalid OpenCV.js column data#370

Merged
cubap merged 5 commits intomainfrom
copilot/fix-auto-parse-error
Dec 16, 2025
Merged

Fix Auto Parse TypeError from invalid OpenCV.js column data#370
cubap merged 5 commits intomainfrom
copilot/fix-auto-parse-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 16, 2025

Auto Parse crashes with TypeError: Cannot create property '3918' on number '1' when OpenCV.js returns malformed column data during text line detection.

Changes

Added validation helper

  • isValidColumn(col) validates array structure and numeric types before destructuring

Defensive column merging

  • Validate columns[0] before accessing elements
  • Check each column element in merge loop, skip invalid entries
  • Use explicit assignments instead of destructuring reassignment
  • Fall back to full-width column [[0, binary.cols]] on invalid data

Safe reduce operation

  • Validate each column element before arithmetic
  • Skip malformed entries instead of crashing

Example

// Before: crashes on invalid data
let [curStart, curEnd] = columns[0]  // TypeError if columns[0] is not an array
for (const [s, e] of columns.slice(1)) { ... }

// After: validates and handles gracefully
if (!isValidColumn(columns[0])) {
  console.warn("Invalid column format detected, using default column")
  columns = [[0, binary.cols]]
} else {
  let curStart = columns[0][0]
  let curEnd = columns[0][1]
  for (const col of columns.slice(1)) {
    if (!isValidColumn(col)) continue
    const [s, e] = col
    ...
  }
}

Invalid data now logs warnings and degrades to single-column detection rather than crashing.

Original prompt

This section details on the original issue you should resolve

<issue_title>Auto Parse is Failing</issue_title>
<issue_description>On my localhost.

I am trying it on the first page with a project created from https://tpen-project-examples.habesoftware.app/transcription-project/manifest.json. I get an error toast and see this in the web console. This is consistent.

Auto Parse failed: TypeError: Cannot create property '3918' on number '1'
    at detectColumns (detect-lines.js:58:28)
    at detectTextLinesCombined (detect-lines.js:155:19)
    at async HTMLButtonElement.<anonymous> (line-parser.js:307:25)
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits December 16, 2025 22:41
Added validation checks to prevent "Cannot create property on number" error:
- Validate columns array elements before destructuring
- Add safe handling for malformed column data
- Replace destructuring assignment with explicit variable assignments
- Add validation in reduce operation to handle edge cases

Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
Improve robustness by validating that column array elements are numbers before performing arithmetic operations. This prevents potential runtime errors from non-numeric values.

Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
Reduce code duplication by extracting column validation logic into a reusable helper function. This improves maintainability and makes the code more readable.

Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
Document the validation helper function with JSDoc comments for better code maintainability and developer experience.

Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix auto parse failing issue on first page Fix Auto Parse TypeError from invalid OpenCV.js column data Dec 16, 2025
Copilot AI requested a review from cubap December 16, 2025 22:48
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 16, 2025

@cubap cubap marked this pull request as ready for review December 16, 2025 22:56
@cubap cubap merged commit a20791a into main Dec 16, 2025
4 checks passed
@cubap cubap deleted the copilot/fix-auto-parse-error branch December 16, 2025 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto Parse is Failing

2 participants