Skip to content

Make symlink name templating resilient to missing event keys#29

Open
Eliot Gann (EliotGann) wants to merge 4 commits into
NSLS2:mainfrom
EliotGann:resilient-symlink-names
Open

Make symlink name templating resilient to missing event keys#29
Eliot Gann (EliotGann) wants to merge 4 commits into
NSLS2:mainfrom
EliotGann:resilient-symlink-names

Conversation

@EliotGann

Copy link
Copy Markdown
Contributor

Previously an unresolved {name} placeholder in the destination filename template (e.g. a sample_name referencing a motor 'x' that was absent from the primary stream) raised KeyError and failed the whole flow.

Add a safe str.format helper that leaves unresolved {name} placeholders literally in the output (preserving any format spec) and logs a warning, plus an opt-in SAFE_KEY_ALIASES table for known short-name fallbacks.

Previously an unresolved {name} placeholder in the destination filename
template (e.g. a sample_name referencing a motor 'x' that was absent from
the primary stream) raised KeyError and failed the whole flow.

Add a safe str.format helper that leaves unresolved {name} placeholders
literally in the output (preserving any format spec) and logs a warning,
plus an opt-in SAFE_KEY_ALIASES table for known short-name fallbacks.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens symlink destination filename templating so missing event keys no longer raise KeyError and fail the flow, by introducing a “safe” formatting helper that leaves unresolved placeholders intact and optionally supports short-name aliases.

Changes:

  • Added _safe_format and supporting classes to safely render str.format templates while preserving unresolved placeholders.
  • Added SAFE_KEY_ALIASES to optionally map known short names (e.g., x) to canonical event keys (e.g., piezo_x) when present.
  • Updated get_symlink_pairs to use two safe formatting passes instead of chained .format(...).format(...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread linker.py Outdated
Comment thread linker.py Outdated
Comment on lines +269 to +274
dest_name = _safe_format(
target_template, format_data, logger=logger
)
dest_name = _safe_format(
dest_name, format_data, logger=logger
)
Eliot Gann (EliotGann) and others added 3 commits June 25, 2026 12:59
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The second pass's input contains every literal {key} the first pass left
behind, so its missing-key set is a superset; warning only there yields at
most one warning per unresolved name per filename.
The success/failure summary lines were plain strings, so they printed
literal {success_rate} / {len(failed)} braces instead of values. Also the
'success_rate' variable was computing the failure fraction; correct it to
linked/total so the label matches the value.
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.

3 participants