Skip to content

Commit

Permalink
Check for errors before proceeding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Mukhopadhyay committed Jul 5, 2023
1 parent 05ae359 commit 7f8515a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
15 changes: 2 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
pub mod error_codes {
pub const ERROR_SCHEMA_INVALID: i32 = 1;
}
21 changes: 17 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ fn main() {
// Get the schema file from the command line arguments or use the default.
let default_schema_file = "schema.graphql".to_string();
let schema_file = &std::env::args().nth(1).unwrap_or(default_schema_file);

println!("schema_file: {}", schema_file);

// Read the schema file and parse it into a schema object.
let schema_file = std::fs::read_to_string(schema_file).unwrap();
let result = std::fs::read_to_string(schema_file);
if result.is_err() {
println!("Error reading schema file: {}", result.err().unwrap());
std::process::exit(error_codes::ERROR_SCHEMA_FILE_INVALID);
}

let schema_file = result.unwrap();
let result = parse_schema::<String>(&schema_file);
if result.is_err() {
println!("Error parsing schema file: {}", result.err().unwrap());
std::process::exit(minigraf::error_codes::ERROR_SCHEMA_INVALID);
}

let ast = parse_schema::<String>(&schema_file).unwrap().to_owned();
let schema = result.unwrap();
println!("schema: {:#?}", schema);
}

println!("{:#?}", ast);
mod error_codes {
pub const ERROR_SCHEMA_FILE_INVALID: i32 = 0x10000;
}

0 comments on commit 7f8515a

Please sign in to comment.