Skip to content
Latchkey

GitHub Actions startsWith expects a string but received null

startsWith(searchString, searchValue) requires string arguments. When a referenced context value is unset it resolves to null, and passing null where a string is expected produces an evaluation error or an always-false condition.

What this error means

An expression using startsWith fails to evaluate or behaves as always-false when the input context value is missing.

github-actions
Error: Unexpected value 'null'. startsWith expects a string but received null.
  if: startsWith(github.event.head_commit.message, 'release:')

Common causes

Context value absent for this event

Fields like head_commit.message exist only for certain events; on others they are null.

Typo or wrong context path

A misspelled context path resolves to null, which startsWith rejects as a non-string.

How to fix it

Coerce to a string before comparing

  1. Wrap the argument so a null becomes an empty string before startsWith runs.
  2. Use format() or a fallback expression to guarantee a string.
.github/workflows/ci.yml
if: ${{ startsWith(format('{0}', github.event.head_commit.message), 'release:') }}

Guard on the event type first

  1. Add a condition that only references the field for events that provide it.
  2. Combine with && so the startsWith only runs when the value exists.

How to prevent it

  • Assume event-specific context fields may be null on other triggers.
  • Wrap optional strings with format() or a default before string functions.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →