Skip to content

Commit

Permalink
Downcast component panics, if possible for better error messages. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bathtor committed Apr 24, 2020
1 parent dcf616f commit dccaa25
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 59 deletions.
12 changes: 11 additions & 1 deletion core/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,17 @@ impl<C: ComponentDefinition + Sized> CoreContainer for Component<C> {
match res {
Ok(_) => (), // great
Err(e) => {
error!(self.logger, "Component panicked with: {:?}", e);
if let Some(error_msg) = e.downcast_ref::<&str>() {
error!(self.logger, "Component panicked with: {:?}", error_msg);
} else if let Some(error_msg) = e.downcast_ref::<String>() {
error!(self.logger, "Component panicked with: {:?}", error_msg);
} else {
error!(
self.logger,
"Component panicked with a non-string message with type id={:?}",
e.type_id()
);
}
lifecycle::set_faulty(&self.state);
if let Some(ref supervisor) = self.supervisor {
supervisor.enqueue(SupervisorMsg::Faulty(self.core.id));
Expand Down
168 changes: 111 additions & 57 deletions feature-tests/protobuf-test/src/messages/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
#![allow(unused_results)]
//! Generated file from `example.proto`
use protobuf::Message as Message_imported_for_functions;
use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions;
use protobuf::{
Message as Message_imported_for_functions,
ProtobufEnum as ProtobufEnum_imported_for_functions,
};

/// Generated files are compatible only with the same version
/// of protobuf runtime.
// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_14_0;

#[derive(PartialEq,Clone,Default)]
#[derive(PartialEq, Clone, Default)]
pub struct SearchRequest {
// message fields
pub query: ::std::string::String,
Expand All @@ -50,10 +52,10 @@ impl SearchRequest {

// string query = 1;


pub fn get_query(&self) -> &str {
&self.query
}

pub fn clear_query(&mut self) {
self.query.clear();
}
Expand All @@ -76,10 +78,10 @@ impl SearchRequest {

// int32 page_number = 2;


pub fn get_page_number(&self) -> i32 {
self.page_number
}

pub fn clear_page_number(&mut self) {
self.page_number = 0;
}
Expand All @@ -91,10 +93,10 @@ impl SearchRequest {

// int32 result_per_page = 3;


pub fn get_result_per_page(&self) -> i32 {
self.result_per_page
}

pub fn clear_result_per_page(&mut self) {
self.result_per_page = 0;
}
Expand All @@ -110,30 +112,46 @@ impl ::protobuf::Message for SearchRequest {
true
}

fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> {
fn merge_from(
&mut self,
is: &mut ::protobuf::CodedInputStream<'_>,
) -> ::protobuf::ProtobufResult<()> {
while !is.eof()? {
let (field_number, wire_type) = is.read_tag_unpack()?;
match field_number {
1 => {
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.query)?;
},
::protobuf::rt::read_singular_proto3_string_into(
wire_type,
is,
&mut self.query,
)?;
}
2 => {
if wire_type != ::protobuf::wire_format::WireTypeVarint {
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(
wire_type,
));
}
let tmp = is.read_int32()?;
self.page_number = tmp;
},
}
3 => {
if wire_type != ::protobuf::wire_format::WireTypeVarint {
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(
wire_type,
));
}
let tmp = is.read_int32()?;
self.result_per_page = tmp;
},
}
_ => {
::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
},
::protobuf::rt::read_unknown_or_skip_group(
field_number,
wire_type,
is,
self.mut_unknown_fields(),
)?;
}
};
}
::std::result::Result::Ok(())
Expand All @@ -147,17 +165,28 @@ impl ::protobuf::Message for SearchRequest {
my_size += ::protobuf::rt::string_size(1, &self.query);
}
if self.page_number != 0 {
my_size += ::protobuf::rt::value_size(2, self.page_number, ::protobuf::wire_format::WireTypeVarint);
my_size += ::protobuf::rt::value_size(
2,
self.page_number,
::protobuf::wire_format::WireTypeVarint,
);
}
if self.result_per_page != 0 {
my_size += ::protobuf::rt::value_size(3, self.result_per_page, ::protobuf::wire_format::WireTypeVarint);
my_size += ::protobuf::rt::value_size(
3,
self.result_per_page,
::protobuf::wire_format::WireTypeVarint,
);
}
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
self.cached_size.set(my_size);
my_size
}

fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
fn write_to_with_cached_sizes(
&self,
os: &mut ::protobuf::CodedOutputStream<'_>,
) -> ::protobuf::ProtobufResult<()> {
if !self.query.is_empty() {
os.write_string(1, &self.query)?;
}
Expand Down Expand Up @@ -186,9 +215,11 @@ impl ::protobuf::Message for SearchRequest {
fn as_any(&self) -> &dyn (::std::any::Any) {
self as &dyn (::std::any::Any)
}

fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}

fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}
Expand All @@ -202,39 +233,47 @@ impl ::protobuf::Message for SearchRequest {
}

fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy::INIT;
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> =
::protobuf::lazy::Lazy::INIT;
unsafe {
descriptor.get(|| {
let mut fields = ::std::vec::Vec::new();
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<
_,
::protobuf::types::ProtobufTypeString,
>(
"query",
|m: &SearchRequest| { &m.query },
|m: &mut SearchRequest| { &mut m.query },
|m: &SearchRequest| &m.query,
|m: &mut SearchRequest| &mut m.query,
));
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeInt32>(
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<
_,
::protobuf::types::ProtobufTypeInt32,
>(
"page_number",
|m: &SearchRequest| { &m.page_number },
|m: &mut SearchRequest| { &mut m.page_number },
|m: &SearchRequest| &m.page_number,
|m: &mut SearchRequest| &mut m.page_number,
));
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeInt32>(
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<
_,
::protobuf::types::ProtobufTypeInt32,
>(
"result_per_page",
|m: &SearchRequest| { &m.result_per_page },
|m: &mut SearchRequest| { &mut m.result_per_page },
|m: &SearchRequest| &m.result_per_page,
|m: &mut SearchRequest| &mut m.result_per_page,
));
::protobuf::reflect::MessageDescriptor::new_pb_name::<SearchRequest>(
"SearchRequest",
fields,
file_descriptor_proto()
file_descriptor_proto(),
)
})
}
}

fn default_instance() -> &'static SearchRequest {
static mut instance: ::protobuf::lazy::Lazy<SearchRequest> = ::protobuf::lazy::Lazy::INIT;
unsafe {
instance.get(SearchRequest::new)
}
unsafe { instance.get(SearchRequest::new) }
}
}

Expand All @@ -259,7 +298,7 @@ impl ::protobuf::reflect::ProtobufValue for SearchRequest {
}
}

#[derive(PartialEq,Clone,Default)]
#[derive(PartialEq, Clone, Default)]
pub struct SearchResponse {
// message fields
pub results: ::protobuf::RepeatedField<::std::string::String>,
Expand All @@ -281,10 +320,10 @@ impl SearchResponse {

// repeated string results = 1;


pub fn get_results(&self) -> &[::std::string::String] {
&self.results
}

pub fn clear_results(&mut self) {
self.results.clear();
}
Expand All @@ -310,16 +349,24 @@ impl ::protobuf::Message for SearchResponse {
true
}

fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> {
fn merge_from(
&mut self,
is: &mut ::protobuf::CodedInputStream<'_>,
) -> ::protobuf::ProtobufResult<()> {
while !is.eof()? {
let (field_number, wire_type) = is.read_tag_unpack()?;
match field_number {
1 => {
::protobuf::rt::read_repeated_string_into(wire_type, is, &mut self.results)?;
},
}
_ => {
::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
},
::protobuf::rt::read_unknown_or_skip_group(
field_number,
wire_type,
is,
self.mut_unknown_fields(),
)?;
}
};
}
::std::result::Result::Ok(())
Expand All @@ -331,16 +378,19 @@ impl ::protobuf::Message for SearchResponse {
let mut my_size = 0;
for value in &self.results {
my_size += ::protobuf::rt::string_size(1, &value);
};
}
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
self.cached_size.set(my_size);
my_size
}

fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
fn write_to_with_cached_sizes(
&self,
os: &mut ::protobuf::CodedOutputStream<'_>,
) -> ::protobuf::ProtobufResult<()> {
for v in &self.results {
os.write_string(1, &v)?;
};
}
os.write_unknown_fields(self.get_unknown_fields())?;
::std::result::Result::Ok(())
}
Expand All @@ -360,9 +410,11 @@ impl ::protobuf::Message for SearchResponse {
fn as_any(&self) -> &dyn (::std::any::Any) {
self as &dyn (::std::any::Any)
}

fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}

fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}
Expand All @@ -376,29 +428,33 @@ impl ::protobuf::Message for SearchResponse {
}

fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy::INIT;
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> =
::protobuf::lazy::Lazy::INIT;
unsafe {
descriptor.get(|| {
let mut fields = ::std::vec::Vec::new();
fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
"results",
|m: &SearchResponse| { &m.results },
|m: &mut SearchResponse| { &mut m.results },
));
fields.push(
::protobuf::reflect::accessor::make_repeated_field_accessor::<
_,
::protobuf::types::ProtobufTypeString,
>(
"results",
|m: &SearchResponse| &m.results,
|m: &mut SearchResponse| &mut m.results,
),
);
::protobuf::reflect::MessageDescriptor::new_pb_name::<SearchResponse>(
"SearchResponse",
fields,
file_descriptor_proto()
file_descriptor_proto(),
)
})
}
}

fn default_instance() -> &'static SearchResponse {
static mut instance: ::protobuf::lazy::Lazy<SearchResponse> = ::protobuf::lazy::Lazy::INIT;
unsafe {
instance.get(SearchResponse::new)
}
unsafe { instance.get(SearchResponse::new) }
}
}

Expand Down Expand Up @@ -429,16 +485,14 @@ static file_descriptor_proto_data: &'static [u8] = b"\
roto3\
";

static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy::INIT;
static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<
::protobuf::descriptor::FileDescriptorProto,
> = ::protobuf::lazy::Lazy::INIT;

fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto {
::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap()
}

pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto {
unsafe {
file_descriptor_proto_lazy.get(|| {
parse_descriptor_proto()
})
}
unsafe { file_descriptor_proto_lazy.get(|| parse_descriptor_proto()) }
}
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use_field_init_shorthand = false
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Auto"
required_version = "1.4.13"
required_version = "1.4.14"
unstable_features = false
disable_all_formatting = false
skip_children = false
Expand Down

0 comments on commit dccaa25

Please sign in to comment.