denoland/deno · error · anyhow::Error

failed to evaluate expression

Error message

failed to evaluate expression

What it means

In the REPL, each evaluated expression is stringified through the DevTools inspector: deno takes the RemoteObject's `value` or falls back to `description`. If the inspector response carries neither field, deno cannot render a result and throws `failed to evaluate expression`. This is a degenerate protocol response (empty payload or race), not a syntax error in the user's expression.

Source

Thrown at cli/tools/repl/session.rs:779

    let response = self
      .call_function_on_repl_internal_obj(
        r#"function (object) {
          try {
            return this.inspectArgs(["%o", object], { colors: !this.noColor });
          } catch (err) {
            return this.inspectArgs(["%o", err]);
          }
        }"#
          .to_string(),
        std::slice::from_ref(evaluate_result),
      )
      .await?;
    let s = response
      .result
      .value
      .map(|v| v.as_str().unwrap().to_string())
      .or(response.result.description)
      .ok_or_else(|| anyhow!("failed to evaluate expression"))?;

    Ok(s)
  }

  async fn evaluate_ts_expression(
    &mut self,
    expression: &str,
  ) -> Result<TsEvaluateResponse, AnyError> {
    let tsx_result =
      parse_source_as(expression.to_string(), deno_ast::MediaType::Tsx);
    // Prefer a clean `.tsx` parse. Fall back to parsing as TypeScript when the
    // `.tsx` parse fails outright, or when it only recovered by inserting an
    // `Invalid` placeholder node (e.g. a TypeScript type assertion like
    // `<string>x` is misread as JSX in `.tsx`).
    let needs_ts_fallback = match &tsx_result {
      Ok(parsed) => {
        deno_resolver::emit::invalid_syntax_parse_diagnostics(parsed).is_some()
      }

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Re-run the expression — it is usually transient
  2. Render the result a different way: console.log(expr) or Deno.inspect(value)
  3. Restart the REPL session if it keeps recurring
  4. If reproducible on the latest Deno, minimize the expression and open an issue

Example fix

// before — bare evaluation of a result the inspector cannot stringify
>>> myObject
// after — inspect explicitly
>>> console.log(myObject)
>>> Deno.inspect(myObject, { depth: 4 })
Defensive patterns

Strategy: retry

Prevention

When it happens

Trigger: Evaluating an expression whose inspector RemoteObject arrives with neither value nor description — certain exotic objects or a transient inspector hiccup mid-session.

Common situations: Long-running REPL sessions; evaluating constructs that return unusual remote-object shapes; intermittent occurrences after heavy session activity.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/4247298af5a1aa64. Report an issue: GitHub.