Skip to content
Latchkey

GitHub Actions format() placeholder index out of range

format(string, a, b, ...) substitutes {0}, {1}, ... with its positional arguments. Referencing a placeholder index higher than the number of supplied arguments is an evaluation error.

What this error means

An expression using format() fails to evaluate with an index/placeholder out-of-range error.

github-actions
Error: The format string references index 2 but only 2 arguments were supplied (indexes 0 and 1).
  run-name: ${{ format('{0} on {1} by {2}', github.workflow, github.ref_name) }}

Common causes

More placeholders than arguments

A {2} placeholder needs a third argument; supplying only two triggers the out-of-range error.

Off-by-one from zero-based indexing

Placeholders are zero-based, so {1} is the second argument; treating them as one-based shifts everything.

How to fix it

Supply an argument for every placeholder

  1. Count placeholders and pass exactly that many arguments in order.
  2. Remember indexing starts at {0}.
.github/workflows/ci.yml
run-name: ${{ format('{0} on {1} by {2}', github.workflow, github.ref_name, github.actor) }}

Escape literal braces

  1. To print a literal brace, double it as {{ or }}.
  2. This prevents an accidental placeholder reference.

How to prevent it

  • Match placeholder count to argument count before committing.
  • Recall placeholders are zero-based.

Frequently asked questions

What causes "format() index out of range"?
A {2} placeholder needs a third argument; supplying only two triggers the out-of-range error.
How do I fix format() index out of range?
Supply an argument for every placeholder

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card