Skip to content

Commit

Permalink
Mention MONGODB_DATABASE_URI environment variable in error message if…
Browse files Browse the repository at this point in the history
… it is missing (#50)

* Mention MONGODB_DATABASE_URI environment variable in error message if it is missing

* Add changelog
  • Loading branch information
dmoverton committed Apr 23, 2024
1 parent 460b251 commit 9066a73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This changelog documents the changes between release versions.
## [Unreleased]
- Fix incorrect order of results for query requests with more than 10 variable sets (#37)
- In the CLI update command, don't overwrite schema files that haven't changed ([#49](https://github.com/hasura/ndc-mongodb/pull/49/files))
- In the CLI update command, if the database URI is not provided the error message now mentions the correct environment variable to use (`MONGODB_DATABASE_URI`) ([#50](https://github.com/hasura/ndc-mongodb/pull/50))

## [0.0.4] - 2024-04-12
- Queries that attempt to compare a column to a column in the query root table, or a related table, will now fail instead of giving the incorrect result ([#22](https://github.com/hasura/ndc-mongodb/pull/22))
Expand Down
17 changes: 11 additions & 6 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::anyhow;
use std::env;
use std::path::PathBuf;

use clap::Parser;
use clap::{Parser, ValueHint};
use mongodb_agent_common::state::{try_init_state_from_uri, DATABASE_URI_ENV_VAR};
use mongodb_cli_plugin::{run, Command, Context};

Expand All @@ -18,17 +18,18 @@ pub struct Args {
#[arg(
long = "context-path",
env = "HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH",
value_name = "DIRECTORY"
value_name = "DIRECTORY",
value_hint = ValueHint::DirPath
)]
pub context_path: Option<PathBuf>,

#[arg(
long = "connection-uri",
env = DATABASE_URI_ENV_VAR,
required = true,
value_name = "URI"
value_name = "URI",
value_hint = ValueHint::Url
)]
pub connection_uri: String,
pub connection_uri: Option<String>,

/// The command to invoke.
#[command(subcommand)]
Expand All @@ -45,7 +46,11 @@ pub async fn main() -> anyhow::Result<()> {
Some(path) => path,
None => env::current_dir()?,
};
let connector_state = try_init_state_from_uri(&args.connection_uri)
let connection_uri = args.connection_uri.ok_or(anyhow!(
"Missing environment variable {}",
DATABASE_URI_ENV_VAR
))?;
let connector_state = try_init_state_from_uri(&connection_uri)
.await
.map_err(|e| anyhow!("Error initializing MongoDB state {}", e))?;
let context = Context {
Expand Down

0 comments on commit 9066a73

Please sign in to comment.