Skip to content

Commit

Permalink
Improve protoc not found error message
Browse files Browse the repository at this point in the history
- 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 /home/allan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/prost-build-0.12.1/src/lib.rs:1475:10:
  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
```
  • Loading branch information
LocalAdmin committed Oct 28, 2023
1 parent 9dd6553 commit e96b13f
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,24 +1449,24 @@ pub fn compile_fds(fds: FileDescriptorSet) -> Result<()> {

/// Returns the path to the `protoc` binary.
pub fn protoc_from_env() -> PathBuf {
let error_msg = "Could not find `protoc`. If `protoc` is installed, try setting the `PROTOC`\nenvironment 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.";
let download_msg =
"It is also available at https://github.com/protocolbuffers/protobuf/releases";

let msg = format!(
"{}{}
"{}\n{}\n{}
For more information: https://docs.rs/prost-build/#sourcing-protoc
",
error_msg, os_specific_hint
error_msg, os_specific_hint, download_msg
);

env::var_os("PROTOC")
Expand Down

0 comments on commit e96b13f

Please sign in to comment.