From fad8d4e4a42924001374e437bcb0a20aab9aec9e Mon Sep 17 00:00:00 2001 From: Yifei Date: Tue, 15 Aug 2023 14:29:11 +0800 Subject: [PATCH] fix: codegen error caused by empty method of services (#217) --- Cargo.lock | 17 ++++------------- volo-build/Cargo.toml | 2 +- volo-build/src/thrift_backend.rs | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 24384c21..4a86be88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -945,15 +945,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.9" @@ -1414,7 +1405,7 @@ dependencies = [ "faststr", "fxhash", "heck 0.4.1", - "itertools 0.10.5", + "itertools", "lazy_static", "normpath", "paste", @@ -2531,13 +2522,13 @@ dependencies = [ [[package]] name = "volo-build" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "async-trait", "dirs", "heck 0.4.1", - "itertools 0.11.0", + "itertools", "lazy_static", "nom", "normpath", @@ -2564,7 +2555,7 @@ dependencies = [ "clap", "colored", "heck 0.4.1", - "itertools 0.10.5", + "itertools", "lazy_static", "log", "normpath", diff --git a/volo-build/Cargo.toml b/volo-build/Cargo.toml index c6c8dcae..9fb738b4 100644 --- a/volo-build/Cargo.toml +++ b/volo-build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "volo-build" -version = "0.6.0" +version = "0.6.1" edition.workspace = true homepage.workspace = true repository.workspace = true diff --git a/volo-build/src/thrift_backend.rs b/volo-build/src/thrift_backend.rs index 9ae3c56c..28147682 100644 --- a/volo-build/src/thrift_backend.rs +++ b/volo-build/src/thrift_backend.rs @@ -64,8 +64,14 @@ impl VoloThriftBackend { let decode = mk_decode(false); let decode_async = mk_decode(true); - let match_encode = crate::join_multi_strs!(",", |variant_names| -> "Self::{variant_names}(value) => {{::pilota::thrift::Message::encode(value, protocol).map_err(|err| err.into())}}"); - let match_size = crate::join_multi_strs!(",", |variant_names| -> "Self::{variant_names}(value) => {{::volo_thrift::Message::size(value, protocol)}}"); + let mut match_encode = crate::join_multi_strs!(",", |variant_names| -> "Self::{variant_names}(value) => {{::pilota::thrift::Message::encode(value, protocol).map_err(|err| err.into())}}"); + let mut match_size = crate::join_multi_strs!(",", |variant_names| -> "Self::{variant_names}(value) => {{::volo_thrift::Message::size(value, protocol)}}"); + + if variant_names.is_empty() { + match_encode = "_ => unreachable!(),".to_string(); + match_size = "_ => unreachable!(),".to_string(); + } + format! { r#"#[::async_trait::async_trait] impl ::volo_thrift::EntryMessage for {req_recv_name} {{ @@ -140,8 +146,13 @@ impl VoloThriftBackend { ) }; - let match_encode = crate::join_multi_strs!(",", |variant_names| -> "Self::{variant_names}(value) => {{::pilota::thrift::Message::encode(value, protocol).map_err(|err| err.into())}}"); - let match_size = crate::join_multi_strs!(",", |variant_names| -> "Self::{variant_names}(value) => {{::volo_thrift::Message::size(value, protocol)}}"); + let mut match_encode = crate::join_multi_strs!(",", |variant_names| -> "Self::{variant_names}(value) => {{::pilota::thrift::Message::encode(value, protocol).map_err(|err| err.into())}}"); + let mut match_size = crate::join_multi_strs!(",", |variant_names| -> "Self::{variant_names}(value) => {{::volo_thrift::Message::size(value, protocol)}}"); + + if variant_names.is_empty() { + match_encode = "_ => unreachable!(),".to_string(); + match_size = "_ => unreachable!(),".to_string(); + } let decode = mk_decode(false); let decode_async = mk_decode(true);