From 64a74013cdc02643ff2cc9d58c5f3393c8eef1c1 Mon Sep 17 00:00:00 2001 From: LocalAdmin Date: Fri, 27 Oct 2023 20:58:25 -0400 Subject: [PATCH] Improve protoc not found error message - fixes missing whitespace between the error message and the OS-specific hint - more succinct wording in error message - capitalization ("debian" -> "Debian") - consistent grammar tenses, slightly more formal and direct tone - `os_specific_hint` now has hard breaks at 80 chars (just like `error_msg`) Before: ``` --- stderr thread 'main' panicked at /home/allan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/prost-build-0.12.1/src/lib.rs:1475:10: Could not find `protoc` installation and this build crate cannot proceed without this knowledge. If `protoc` is installed and this crate had trouble finding it, you can set the `PROTOC` environment variable with the specific path to your installed `protoc` binary.If you're on debian, try `apt-get install protobuf-compiler` or download it from https://github.com/protocolbuffers/protobuf/releases For more information: https://docs.rs/prost-build/#sourcing-protoc ``` Proposed: ``` --- stderr thread 'main' panicked at tests/single-include/build.rs:7:10: called `Result::unwrap()` on an `Err` value: Custom { kind: NotFound, error: "Could not find `protoc`. If `protoc` is installed, try setting the `PROTOC` environment variable to the path of the `protoc` binary. To install it on Debian, run `apt-get install protobuf-compiler`. It is also available at https://github.com/protocolbuffers/protobuf/releases For more information: https://docs.rs/prost-build/#sourcing-protoc" } ``` --- prost-build/src/lib.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/prost-build/src/lib.rs b/prost-build/src/lib.rs index 992efd4c8..d972a85df 100644 --- a/prost-build/src/lib.rs +++ b/prost-build/src/lib.rs @@ -1516,24 +1516,21 @@ pub fn protoc_from_env() -> PathBuf { } pub fn error_message_protoc_not_found() -> String { + let error_msg = "Could not find `protoc`. If `protoc` is installed, try setting the `PROTOC` environment variable to the path of the `protoc` binary."; + let os_specific_hint = if cfg!(target_os = "macos") { - "You could try running `brew install protobuf` or downloading it from https://github.com/protocolbuffers/protobuf/releases" + "To install it on macOS, run `brew install protobuf`." } else if cfg!(target_os = "linux") { - "If you're on debian, try `apt-get install protobuf-compiler` or download it from https://github.com/protocolbuffers/protobuf/releases" + "To install it on Debian, run `apt-get install protobuf-compiler`." } else { - "You can download it from https://github.com/protocolbuffers/protobuf/releases or from your package manager." + "Try installing `protobuf-compiler` or `protobuf` using your package manager." }; - let error_msg = - "Could not find `protoc` installation and this build crate cannot proceed without - this knowledge. If `protoc` is installed and this crate had trouble finding - it, you can set the `PROTOC` environment variable with the specific path to your - installed `protoc` binary."; - format!( - "{}{} + let download_msg = + "It is also available at https://github.com/protocolbuffers/protobuf/releases"; -For more information: https://docs.rs/prost-build/#sourcing-protoc -", - error_msg, os_specific_hint + format!( + "{} {} {} For more information: https://docs.rs/prost-build/#sourcing-protoc", + error_msg, os_specific_hint, download_msg ) }