Skip to content

Ref single lookup registries - #293

Merged
g5t merged 3 commits into
mainfrom
ref-single-lookup-registries
Aug 13, 2026
Merged

Ref single lookup registries#293
g5t merged 3 commits into
mainfrom
ref-single-lookup-registries

Conversation

@g5t

@g5t g5t commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

g5t added 3 commits August 12, 2026 18:59
resolve_from_registries() exists because four lookups each ran

    for reg in registries:
        if reg.known(name):
            return reg.<action>(name)

which treats the first registry that *claims* a name as binding. known() is a
claim, not a guarantee: a registry can answer truthfully and still fail to
deliver -- ambiguous candidates it cannot choose between, an unreadable file, a
network error on a remote -- and one such registry could abort a lookup a later
registry would have satisfied.

TargetVisitor.file_text was written on a branch that predated the helper, so it
carried its own copy of exactly that loop and was the last lookup still
committing to the first claimant. Route it through the helper, matching
TargetVisitor.locate three methods above it.

This is not only de-duplication. A registry that knows a name but raises while
producing it is now logged and skipped rather than aborting the lookup, and a
lookup that fails everywhere reports each registry's reason instead of a bare
"not found". Concretely, InMemoryRegistry.contents() raises for an entry that is
not UTF-8 text, so an %include naming a binary embedded entry now falls through
to a disk registry holding a readable copy; where nothing else has the file the
lookup still fails, with the original error text preserved in the aggregated
message.
known(), unique() and contain() each re-inlined the expression _candidates()
already provides. No behaviour change.
_fetch_one was the last copy of the lookup loop that binds to the first registry
whose known() answers True. It sat outside the previous commit because its error
handling is CLI-specific: it raises FileNotFoundError with a pointer to
`mccode-antlr datafile list`, which resolve_from_registries would have replaced
with a bare RuntimeError.

Route it through the helper and translate the failure back, so the fall-through
is gained without losing the CLI's error type or its pointer.

The message now carries the helper's per-registry detail rather than asserting
absence. A fetch can fail because a registry knew the file and could not deliver
it -- a network error reaching a remote, say -- and reporting that as "not found
in any registry" would send the user looking for a missing file instead of at the
real cause. The original exception is chained as __cause__.

    Data file 'x.dat' could not be fetched for mcstas: x.dat not found in
    registries: libc,mcstas
    Use 'mccode-antlr datafile list --flavor mcstas' to see available files.

This is a user-facing wording change; the exception type and the pointer to
`datafile list` are unchanged. tests/test_cli_datafile.py is new -- the
sub-command had no tests.
@g5t
g5t merged commit 28fb07f into main Aug 13, 2026
32 checks passed
@g5t g5t added the enhancement New feature or request label Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant