Skip to content

Commit

Permalink
Improve error messages in configuration and initialization
Browse files Browse the repository at this point in the history
Clarify the error message when no configuration file is found by suggesting using the `--help` option or trying `rusty-buddy init`. This improves user guidance when encountering an error.
  • Loading branch information
Christian Stolz committed Oct 13, 2024
1 parent 5d38aa4 commit ffb4dda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ async fn main() {
run_init_command().await.unwrap();
}
if !check_environment() {
error!("No configuration file found.");
eprintln!(
"No configuration file found. Use --help for more information or try rusty-buddy init."
);
std::process::exit(1);
}
if let Err(e) = setup_logging() {
Expand Down
5 changes: 5 additions & 0 deletions src/provider/openai/openai_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ fn truncate_to_max_bytes(s: &str, max_bytes: usize) -> &str {
impl OpenAIInterface {
pub fn new(model: String, timeout_secs: u64) -> Self {
dotenv().ok();
// Check if the OPENAI_KEY is set in the environment
if env::var("OPENAI_KEY").is_err() {
eprintln!("Error: The environment variable 'OPENAI_KEY' must be set.");
std::process::exit(1);
}

OpenAIInterface {
model,
Expand Down

0 comments on commit ffb4dda

Please sign in to comment.