Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error on nested sequence #132

Open
flxbe opened this issue Jun 30, 2021 · 0 comments
Open

Compile error on nested sequence #132

flxbe opened this issue Jun 30, 2021 · 0 comments

Comments

@flxbe
Copy link

flxbe commented Jun 30, 2021

Hi!

I get an compile error when parsing the following WSDL file: http://api.betdaq.com/v2.0/API.wsdl

Specifically, this seems to be the problematic part:

<xs:complexType name="CancelOrdersRequest">
  <xs:sequence>
    <xs:sequence minOccurs="1" maxOccurs="unbounded">
      <xs:element name="OrderHandle" type="xs:long"/>
    </xs:sequence>
  </xs:sequence>
</xs:complexType>

This is the error message I get:

thread 'main' panicked at 'internal error: entered unreachable code: 
Error: Element { tag_name: {http://www.w3.org/2001/XMLSchema}sequence, attributes: [Attribute { name: minOccurs, value: "1" }, Attribute { name: maxOccurs, value: "unbounded" }], namespaces: [Namespace { name: Some("http"), uri: "http://schemas.xmlsoap.org/wsdl/http/" }, Namespace { name: Some("soap"), uri: "http://schemas.xmlsoap.org/wsdl/soap/" }, Namespace { name: Some("xs"), uri: "http://www.w3.org/2001/XMLSchema" }, Namespace { name: Some("soapenc"), uri: "http://schemas.xmlsoap.org/soap/encoding/" }, Namespace { name: None, uri: "http://www.GlobalBettingExchange.com/ExternalAPI/" }, Namespace { name: Some("tm"), uri: "http://microsoft.com/wsdl/mime/textMatching/" }, Namespace { name: Some("mime"), uri: "http://schemas.xmlsoap.org/wsdl/mime/" }, Namespace { name: Some("wsdl"), uri: "http://schemas.xmlsoap.org/wsdl/" }] }
Struct(Struct { name: "CancelOrdersRequest", comment: None, fields: RefCell { value: [StructField { name: "OrderHandle", type_name: "xs:long", comment: None, subtypes: [], source: Element, type_modifiers: [None] }] }, attribute_groups: RefCell { value: [] }, subtypes: [] })', xsd-parser/src/parser/sequence.rs:43:18
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: std::panicking::begin_panic_fmt
   8: xsd_parser::parser::sequence::elements_to_fields::{{closure}}
   9: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
  10: core::option::Option<T>::map
  11: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::next
  12: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  13: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
  14: core::iter::traits::iterator::Iterator::collect
  15: xsd_parser::parser::sequence::elements_to_fields
  16: xsd_parser::parser::sequence::parse_sequence
  17: xsd_parser::parser::node_parser::parse_node
  18: xsd_parser::parser::complex_type::parse_complex_type
  19: xsd_parser::parser::node_parser::parse_node
  20: xsd_parser::parser::schema::parse_schema::{{closure}}
  21: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
  22: core::option::Option<T>::map
  23: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::next
  24: alloc::vec::Vec<T>::extend_desugared
  25: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::spec_extend
  26: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  27: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
  28: core::iter::traits::iterator::Iterator::collect
  29: xsd_parser::parser::schema::parse_schema
  30: wsdl_parser::process_single_file::{{closure}}
  31: core::iter::adapters::map_fold::{{closure}}
  32: core::iter::traits::iterator::Iterator::fold
  33: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  34: core::iter::traits::iterator::Iterator::for_each
  35: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::spec_extend
  36: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  37: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
  38: core::iter::traits::iterator::Iterator::collect
  39: wsdl_parser::process_single_file
  40: wsdl_parser::main
  41: std::rt::lang_start::{{closure}}
  42: std::rt::lang_start_internal
  43: std::rt::lang_start
  44: main

I played a little with the code mentioned in the error message, i.e. xsd-parser/src/parser/sequence.rs:43:18. I added a case to RsEntity::Struct:

            RsEntity::Struct(s) => StructField {
                name: format!("{}", s.name),
                type_name: s.name.clone(),
                subtypes: vec![RsEntity::Struct(s)],
                source: StructFieldSource::Element,
                ..Default::default()
            },

Since I am neither an expert in rust or WSDL, the approach is of course pretty naive, but at least it now runs without crashing. The generated code however seems to be wrong. The result should represent a list of type OrderHandle.

Maybe the problem is the interpretation of a sequence as a struct, whereas it can sometimes also represent a list? Maybe the parse_sequence function could check for the according attributes (i.e. minOccurs and maxOccurs) to check whether the result should be a struct, a list or an optional type, and then call e.g. parse_list accordingly.

If you could point me into the right direction I would be happy to implement the fix myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant