Skip to content

fix(elements): degrade gracefully on empty produce/consume link attribute - #53

Merged
hutcheb merged 1 commit into
hutcheb:mainfrom
colinlove:fix/empty-produce-consume-link
Nov 3, 2026
Merged

hutcheb merged 1 commit into
hutcheb:mainfrom
colinlove:fix/empty-produce-consume-link

Conversation

@colinlove

Copy link
Copy Markdown
Contributor

This fix is part of a series found with AI assistance (Claude Code) — see the first PR in this batch for the full disclosure.


Produced/consumed tag with an empty (0-length) link attribute aborts the whole export

Symptom

ValueError: Tag connection does not reference linked data

raised from _legacy_linked_data, aborting the entire export for the sake
of one tag.

Root cause

TagBuilder.build() decides a tag is Produced/Consumed based on
0x6B in extended_records (the produced/consumed link attribute). On a
real project file, this attribute is present but holds a genuinely
0-length value — extended_records.get(0x6B, b"") returns b"" — instead
of the 4-byte linked object_id it's supposed to hold. _legacy_linked_data
correctly detects this (len(link) < 4) and raises, but the caller had no
fallback: the whole file's export dies over one tag's connection metadata.

Fix

Wrap the _legacy_produce_info / _legacy_consume_info calls in a
try/except ValueError. On failure, log a warning naming the tag and fall
back to exporting it as a plain Base tag (no produce/consume info)
instead of failing the whole project's export. This mirrors the "degrade
gracefully, don't lose the whole file over one bad record" approach already
used elsewhere in this codebase (e.g. DataTypeBuilder.build()'s existing
except Exception: return DataType(...) fallback).

Suggested validation

A tag with 0x6B present but 0-length (or otherwise too short to hold a
4-byte object_id) should now export as Base with a logged warning,
rather than aborting the file.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants