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 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" }
```
  • Loading branch information
LocalAdmin authored and caspermeijn committed Mar 15, 2024
1 parent 7c04d97 commit 64a7401
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down

0 comments on commit 64a7401

Please sign in to comment.