denoland/deno · error · AnyError

Invalid commit hash passed ({}) Pass a semver, or a full 40

Error message

Invalid commit hash passed ({})

Pass a semver, or a full 40 character git commit hash, or a release channel name.

Usage:
{}

What it means

When you pass an explicit version to `deno upgrade --canary`, the value must be a full 40-character git commit hash (matched against a hash regex). A leading `v` is stripped first; anything that is not 40 hex chars triggers this bail with the usage text. The canary channel is addressed by commit hash, not semver.

Source

Thrown at cli/tools/upgrade.rs:1260

          val.to_string(),
        ));
      } else {
        maybe_passed_version = Some(val.to_string());
      }
    }

    let Some(passed_version) = maybe_passed_version else {
      return Ok(Self::Latest(channel));
    };

    let passed_version = passed_version
      .strip_prefix('v')
      .unwrap_or(&passed_version)
      .to_string();

    let (channel, passed_version) = if is_canary {
      if !re_hash.is_match(&passed_version) {
        bail!(
          "Invalid commit hash passed ({})\n\nPass a semver, or a full 40 character git commit hash, or a release channel name.\n\nUsage:\n{}",
          colors::gray(passed_version),
          UPGRADE_USAGE
        );
      }

      (ReleaseChannel::Canary, passed_version)
    } else {
      let Ok(semver) = Version::parse_standard(&passed_version) else {
        bail!(
          "Invalid version passed ({})\n\nPass a semver, or a full 40 character git commit hash, or a release channel name.\n\nUsage:\n{}",
          colors::gray(passed_version),
          UPGRADE_USAGE
        );
      };

      if semver.pre.contains(&SmallStackString::from_static("alpha")) {
        (ReleaseChannel::Alpha, passed_version)

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Pass the full 40-character commit hash: copy it from the commit page (`gh api repos/denoland/deno/commits/<short>` resolves it).
  2. If you meant a semver release, drop `--canary` and pass the version instead.
  3. If you meant a named channel, use the channel name (stable/rc/beta) without a hash.
  4. Check for stray characters (`v` is tolerated, anything else is not).

Example fix

# before
deno upgrade --canary 9f0a1b2  # short hash -> error

# after
deno upgrade --canary 9f0a1b2c3d4e5f60718293a4b5c6d7e8f9011223  # full 40-char hash
Defensive patterns

Strategy: validation

Validate before calling

# bash: accept only a full 40-hex commit hash for canary
[[ "$HASH" =~ ^[0-9a-fA-F]{40}$ ]] || { echo "pass a full 40-char commit hash"; exit 1; }
deno upgrade --canary "$HASH"

Type guard

is_full_commit_hash() { [[ "$1" =~ ^[0-9a-fA-F]{40}$ ]]; }

Try / catch

deno upgrade --canary "$HASH" 2>err.log || { grep -q 'Invalid commit hash' err.log && gh api repos/denoland/deno/commits/"${HASH:0:10}" -q .sha; }

Prevention

When it happens

Trigger: `deno upgrade --canary abc123` (short hash), `--canary v1.2.3` (semver on the canary channel), or any value failing `re_hash` at cli/tools/upgrade.rs:1260.

Common situations: Copying a short 7-char hash from GitHub UI/commit logs; pasting a tag or semver while `--canary` is set; trailing whitespace/newlines pasted from terminals.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/ebdfbfc339d750d1. Report an issue: GitHub.