swellaby / rusty-hook

git hook manager, geared toward Rust projects
MIT License
206 stars 11 forks source link

Update build script error behavior #110

Open calebcartwright opened 4 years ago

calebcartwright commented 4 years ago

Currently, the build script is used to perform local setup when rusty-hook is leveraged as a dev dependency to simplify and automated the hook setup process.

Our build script always exits with 0 even when the initialization process fails with an accompanying error message printed.

https://github.com/swellaby/rusty-hook/blob/b90df2491304155a904257181a174e45391d4e87/build.rs#L14-L25

However, cargo doesn't display any output from build scripts unless invoked with the -vv flag which shouldn't be a requirement (it is by definition very vebose :wink:).

I'm not really sure why we did it this way, probably an attempt to avoid any failures during the initial cargo test run, but it's problematic because the initialization will just silently fail in the event of any init issues which makes for a poor user experience (refs #109).

We should just have the build script exit properly when initialization fails so that the output is displayed. Users can always remove rusty-hook from their dev-deps if it becomes a blocking issue for them

This could be fixed with something as simple as the following:

    if let Err(err) = rusty_hook::init_directory(
        nias::get_command_runner(),
        nias::get_file_writer(),
        nias::get_file_existence_checker(),
        Some(&target_directory),
    ) {
        eprintln!(
            "\n[rusty-hook]: Fatal error encountered during initialization. Details: {}\n",
            err
        );
        exit(1);
    };
    exit(0);