Skip to content

feat: template fallback operator ${expr || 'default'}#2551

Open
hardyjosh wants to merge 2 commits intolist-tokensfrom
template-fallback
Open

feat: template fallback operator ${expr || 'default'}#2551
hardyjosh wants to merge 2 commits intolist-tokensfrom
template-fallback

Conversation

@hardyjosh
Copy link
Copy Markdown
Contributor

@hardyjosh hardyjosh commented Apr 15, 2026

Caution

Stacks on #2549. Merge that first.

Motivation

Strategy field names and descriptions in .rain YAML reference token properties via templates like \${order.inputs.0.token.symbol} per \${order.outputs.0.token.symbol}. The webapp resolves these at runtime once tokens have been selected. Any other consumer (notably --describe) that renders these strings before a token is picked sees the raw placeholder, which is confusing.

Dropping the placeholder in un-selected contexts would lose the structural information. Hard-coding a substitution in every consumer is brittle and doesn't match webapp semantics.

Solution

Extend the template syntax with an optional fallback literal:

${path}                    — current behaviour
${path || 'fallback'}      — substitute literal when the path resolves to a missing token
${path || "fallback"}      — double quotes also accepted

The fallback only kicks in on PropertyNotFound("token") (i.e. select-token not yet selected). Other resolution errors still propagate. Templates without || behave identically to today — backwards compatible.

The webapp gets no regression: when tokens are selected the left-hand side always resolves and the fallback never fires. --describe (and any other "no context" consumer) gets readable output for free once registry strategies adopt fallbacks.

Registry adoption is tracked in ST0x-Technology/st0x.registry#9.

Checks

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Copy link
Copy Markdown
Contributor Author

hardyjosh commented Apr 15, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1ebc442b-63e5-4267-bc6a-81fa4dcb3158

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch template-fallback

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hardyjosh hardyjosh changed the base branch from list-tokens to graphite-base/2551 April 15, 2026 12:55
@hardyjosh hardyjosh force-pushed the graphite-base/2551 branch from 38992d1 to 129f279 Compare April 15, 2026 13:04
@hardyjosh hardyjosh changed the base branch from graphite-base/2551 to list-tokens April 15, 2026 13:04
@hardyjosh
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@hardyjosh
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Josh Hardy added 2 commits April 15, 2026 22:06
When a template path resolves to a missing token field (select-token
not yet selected) and a fallback literal is supplied, substitute the
literal instead of leaving the placeholder raw or erroring.

Syntax:
  ${path}                  — current behaviour
  ${path || 'fallback'}    — new: substitute literal on missing token
  ${path || "fallback"}    — double quotes also accepted

Backwards-compatible: existing templates without `||` behave identically.
The fallback only kicks in on PropertyNotFound("token") (i.e. unresolved
select-token), not on other resolution errors.

This unblocks --describe emitting readable field names/descriptions when
no token has been selected yet.
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.

1 participant