Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible improvement on the snapchain v0 code. file path : github.com/farcasterxyz/snapchain-v0/blob/main/build.rs #1

Open
Boss-DG opened this issue Oct 26, 2024 · 0 comments

Comments

@Boss-DG
Copy link

Boss-DG commented Oct 26, 2024

It's generally good practice to add specific error handling and logging, especially for file paths and external tools like tonic_build, and also Use Constants for instance;
If "src/proto/blocks.proto" is a fixed path that might be reused elsewhere, consider defining it as a constant for maintainability.

below is an improved version that includes these suggestions

use std::error::Error;
use std::path::Path;

const PROTO_PATH: &str = "src/proto/blocks.proto";

fn main() -> Result<(), Box> {
// Check if the .proto file exists before attempting to compile
if !Path::new(PROTO_PATH).exists() {
eprintln!("Error: The .proto file at '{}' was not found.", PROTO_PATH);
return Err("Proto file not found".into());
}

// Compile the proto files and handle errors
tonic_build::compile_protos(PROTO_PATH)
    .map_err(|e| {
        eprintln!("Error compiling proto files: {}", e);
        e
    })?;

println!("Proto files compiled successfully.");
Ok(())

}

this is a potential suggestion. Thanks

@Boss-DG Boss-DG changed the title possible improvement on the snapchain v0 src code possible improvement on the snapchain v0 code. file path : github.com/farcasterxyz/snapchain-v0/blob/main/build.rs Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant