Commit 3fc9279
`read_metadata` previously surfaced a raw h5py `KeyError` ("Can't open
attribute (can't locate attribute: 'json')") when an `.slp` file's
`metadata` group exists but is missing its `json` attribute, giving users
no context or recovery path. This has been seen on user-corrupted files
(talmolab/sleap#2146).
Wrap only the `read_hdf5_attrs` call in `read_metadata` in a `try/except
KeyError` and re-raise a `ValueError(...) from e` that names the file,
explains it is likely corrupt, and gives an h5py recovery snippet. The
decode/`json.loads` lines stay outside the try so a present-but-malformed
blob still surfaces as its own decode error rather than being mislabeled
as corruption. The blanket `except KeyError` also covers a fully-absent
`metadata` group; the "likely corrupt" wording stays accurate for both.
The error propagates automatically through `read_labels` via
`read_skeletons`, so no extra plumbing is added.
Adds four focused tests covering the missing-attribute, missing-group,
read_labels-propagation, and malformed-blob-not-remasked cases.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ad6aadb commit 3fc9279
2 files changed
Lines changed: 70 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1496 | 1496 | | |
1497 | 1497 | | |
1498 | 1498 | | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
1499 | 1504 | | |
1500 | | - | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
1501 | 1521 | | |
1502 | 1522 | | |
1503 | 1523 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5414 | 5414 | | |
5415 | 5415 | | |
5416 | 5416 | | |
| 5417 | + | |
| 5418 | + | |
| 5419 | + | |
| 5420 | + | |
| 5421 | + | |
| 5422 | + | |
| 5423 | + | |
| 5424 | + | |
| 5425 | + | |
| 5426 | + | |
| 5427 | + | |
| 5428 | + | |
| 5429 | + | |
| 5430 | + | |
| 5431 | + | |
| 5432 | + | |
| 5433 | + | |
| 5434 | + | |
| 5435 | + | |
| 5436 | + | |
| 5437 | + | |
| 5438 | + | |
| 5439 | + | |
| 5440 | + | |
| 5441 | + | |
| 5442 | + | |
| 5443 | + | |
| 5444 | + | |
| 5445 | + | |
| 5446 | + | |
| 5447 | + | |
| 5448 | + | |
| 5449 | + | |
| 5450 | + | |
| 5451 | + | |
| 5452 | + | |
| 5453 | + | |
| 5454 | + | |
| 5455 | + | |
| 5456 | + | |
| 5457 | + | |
| 5458 | + | |
| 5459 | + | |
| 5460 | + | |
| 5461 | + | |
| 5462 | + | |
| 5463 | + | |
| 5464 | + | |
| 5465 | + | |
5417 | 5466 | | |
5418 | 5467 | | |
5419 | 5468 | | |
| |||
0 commit comments