tokio-rs / prost

PROST! a Protocol Buffers implementation for the Rust Language
Apache License 2.0
3.92k stars 504 forks source link

Panic in `prost-build` with potentially unsupported `extern_path` #932

Open kriswuollett opened 1 year ago

kriswuollett commented 1 year ago

Similar to #838, I'm encountering the following panic when attempting to add an external_path to the builder:

https://github.com/tokio-rs/prost/blob/97cd4e29c46f1cac4d27428c759b6bc807c37201/prost-build/src/lib.rs#L1216-L1221

The form of the externs I'm newly attempting to use are like: .my.package -> ::my_package::pb. I don't know if using a submodule is supported or not, but that would be a separate issue. The issue here is that the panic has no information to the end-user of what pre-condition failed. So it is extremely difficult to know if what I'm doing is supported or not.

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /Users/kris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/prost-build-0.12.1/src/lib.rs:1218:52
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:593:5
     1: core::panicking::panic_fmt
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:67:14
     2: core::panicking::panic
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:117:5
     3: core::option::Option<T>::unwrap
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/option.rs:935:21
     4: prost_build::Config::generate
               at /Users/kris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/prost-build-0.12.1/src/lib.rs:1218:27
     5: prost_build::Config::compile_fds
               at /Users/kris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/prost-build-0.12.1/src/lib.rs:969:23
     6: prost_build::Config::compile_protos
               at /Users/kris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/prost-build-0.12.1/src/lib.rs:1116:9
     7: tonic_build::prost::Builder::compile_with_config
               at /Users/kris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tonic-build-0.10.2/src/prost.rs:607:9
     8: tonic_build::prost::Builder::compile
               at /Users/kris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tonic-build-0.10.2/src/prost.rs:533:9
     9: REDACTED
               at REDACTED
    10: REDACTED
               at REDACTED
    11: build_script_build::main
               at ./build.rs:19:5
    12: core::ops::function::FnOnce::call_once
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:250:5
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Externs are working for me when I used code like the following (not a submodule nor complete package mapping):

    for t in vec!["Any", "Duration"] {
        builder = builder.extern_path(
            format!(".google.protobuf.{t}"),
            format!("::prost_types::{t}"),
        );
    }