Repository: denoland/deno
File: cli/main.rs (Rust)

Code before:
    unsafe {
      std::env::set_var("DENO_CONNECTED", &host);
    }
  }

  let otel_config = flags.otel_config();
  init_logging(flags.log_level, Some(otel_config.clone()));
  deno_telemetry::init(
    deno_lib::version::otel_runtime_config(),
    otel_config.clone(),
  )?;

  // TODO(bartlomieju): remove in Deno v2.5 and hard error then.
  if flags.unstable_config.legacy_flag_enabled {
    log::warn!(
      "⚠️  {}",
      colors::yellow(
        "The `--unstable` flag has been removed in Deno 2.0. Use granular `--unstable-*` flags instead.\nLearn more at: https://docs.deno.com/runtime/manual/tools/unstable_flags"
      )
    );
  }

  if let Ok(audit_path) = std::env::var("DENO_PERMISSIONS_AUDIT") {
    let _ = deno_runtime::deno_permissions::AUDIT_FILE.set(
      deno_core::parking_lot::Mutex::new(
        std::fs::File::create(audit_path).unwrap(),
      ),
    );
  }

  Ok(flags)
}

fn init_v8(flags: &Flags) {
  let default_v8_flags = match flags.subcommand {
    DenoSubcommand::Lsp => vec![
      "--stack-size=1024".to_string(),
      "--js-explicit-resource-management".to_string(),
      // Using same default as VSCode:
      // https://github.com/microsoft/vscode/blob/48d4ba271686e8072fc6674137415bc80d936bc7/extensions/typescript-language-features/src/configuration/configuration.ts#L213-L214
      "--max-old-space-size=3072".to_string(),
    ],
    _ => get_default_v8_flags(),
  };

  let env_v8_flags = get_v8_flags_from_env();
  let is_single_threaded = env_v8_flags
    .iter()
    .chain(&flags.v8_flags)
    .any(|flag| flag == "--single-threaded");
  init_v8_flags(&default_v8_flags, &flags.v8_flags, env_v8_flags);

Review comment (bug):
Can you please handle this gracefully? We should either return a fatal error here or ignore and print a warning

Code after:
    Err(err) => exit_for_error(err),
  }
}

async fn resolve_flags_and_init(
  args: Vec<std::ffi::OsString>,
) -> Result<Flags, AnyError> {
  let mut flags = match flags_from_vec(args) {
    Ok(flags) => flags,
    Err(err @ clap::Error { .. })
      if err.kind() == clap::error::ErrorKind::DisplayVersion =>
    {
      // Ignore results to avoid BrokenPipe errors.
      let _ = err.print();
      deno_runtime::exit(0);
    }
    Err(err) => exit_for_error(AnyError::from(err)),
  };
  // preserve already loaded env variables
  if flags.subcommand.watch_flags().is_some() {
    WatchEnvTracker::snapshot();
  }
  let env_file_paths: Option<Vec<std::path::PathBuf>> = flags
    .env_file
    .as_ref()
    .map(|files| files.iter().map(PathBuf::from).collect());
  load_env_variables_from_env_files(env_file_paths.as_ref(), flags.log_level);
  flags.unstable_config.fill_with_env();
  if std::env::var("DENO_COMPAT").is_ok() {
    flags.unstable_config.enable_node_compat();
  }
  if flags.node_conditions.is_empty()
    && let Ok(conditions) = std::env::var("DENO_CONDITIONS")
  {
    flags.node_conditions = conditions
      .split(",")
      .map(|c| c.trim().to_string())
      .collect();
  }

  // Tunnel is initialized before OTEL since
  // OTEL data is submitted via the tunnel.
  if let Some(host) = flags
    .connected
    .clone()
    .or_else(|| env::var("DENO_CONNECTED").ok())
  {
    if let Err(err) = initialize_tunnel(&host, &flags).await {
      exit_for_error(err.context("Failed to start with --connected"));
    }
    // SAFETY: We're doing this before any threads are created.