You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/04/25 18:11:01 UTC

[GitHub] [avro] martin-g commented on pull request #1668: AVRO-3484: Followup Check default json parsing at compile time for derive macro

martin-g commented on PR #1668:
URL: https://github.com/apache/avro/pull/1668#issuecomment-1108884441

   Thank you, @jklamer !
   
   Do you think we can improve the compilation error report somehow ?
   For example, if I break the default value for `array` field with:
   ```diff
   diff --git lang/rust/avro_derive/tests/derive.rs lang/rust/avro_derive/tests/derive.rs
   index 0886156ed..4199144c0 100644
   --- lang/rust/avro_derive/tests/derive.rs
   +++ lang/rust/avro_derive/tests/derive.rs
   @@ -1240,7 +1240,7 @@ mod test_derive {
                #[avro(default = r#"{"a": 1, "b": 2}"#)]
                map: HashMap<String, i32>,
    
   -            #[avro(default = "[1, 2, 3]")]
   +            #[avro(default = "[1, 2, 3")]
                array: Vec<i32>,
   ```
   
   then the error is:
   
   <details>
   <pre>
   error: Invalid avro default json: 
          EOF while parsing a list at line 1 column 8
       --> avro_derive/tests/derive.rs:1244:13
        |
   1244 |             array: Vec<i32>,
        |             ^^^^^
   
   error[E0599]: the function or associated item `get_schema` exists for struct `TestBasicStructWithDefaultValues`, but its trait bounds were not satisfied
       --> avro_derive/tests/derive.rs:1307:88
        |
   1231 |         struct TestBasicStructWithDefaultValues {
        |         ---------------------------------------
        |         |
        |         function or associated item `get_schema` not found for this
        |         doesn't satisfy `_: apache_avro::schema::AvroSchema`
        |         doesn't satisfy `_: apache_avro::schema::derive::AvroSchemaComponent`
   ...
   1307 |         if let Schema::Record { name, fields, .. } = TestBasicStructWithDefaultValues::get_schema()
        |                                                                                        ^^^^^^^^^^ function or associated item cannot be called on `TestBasicStructWithDefaultValues` due to unsatisfied trait bounds
        |
        = note: the following trait bounds were not satisfied:
                `TestBasicStructWithDefaultValues: apache_avro::schema::derive::AvroSchemaComponent`
                which is required by `TestBasicStructWithDefaultValues: apache_avro::schema::AvroSchema`
                `&TestBasicStructWithDefaultValues: apache_avro::schema::derive::AvroSchemaComponent`
                which is required by `&TestBasicStructWithDefaultValues: apache_avro::schema::AvroSchema`
                `&mut TestBasicStructWithDefaultValues: apache_avro::schema::derive::AvroSchemaComponent`
                which is required by `&mut TestBasicStructWithDefaultValues: apache_avro::schema::AvroSchema`
   note: the following trait must be implemented
       --> /home/martin/git/apache/avro/lang/rust/avro/src/schema.rs:1589:5
        |
   1589 | /     pub trait AvroSchemaComponent {
   1590 | |         fn get_schema_in_ctxt(named_schemas: &mut Names, enclosing_namespace: &Namespace)
   1591 | |             -> Schema;
   1592 | |     }
        | |_____^
   
   error[E0599]: the function or associated item `get_schema` exists for struct `TestBasicStructWithDefaultValues`, but its trait bounds were not satisfied
       --> avro_derive/tests/derive.rs:1335:62
        |
   1231 |         struct TestBasicStructWithDefaultValues {
        |         ---------------------------------------
        |         |
        |         function or associated item `get_schema` not found for this
        |         doesn't satisfy `_: apache_avro::schema::AvroSchema`
        |         doesn't satisfy `_: apache_avro::schema::derive::AvroSchemaComponent`
   ...
   1335 |         assert_eq!(schema, TestBasicStructWithDefaultValues::get_schema());
        |                                                              ^^^^^^^^^^ function or associated item cannot be called on `TestBasicStructWithDefaultValues` due to unsatisfied trait bounds
        |
        = note: the following trait bounds were not satisfied:
                `TestBasicStructWithDefaultValues: apache_avro::schema::derive::AvroSchemaComponent`
                which is required by `TestBasicStructWithDefaultValues: apache_avro::schema::AvroSchema`
                `&TestBasicStructWithDefaultValues: apache_avro::schema::derive::AvroSchemaComponent`
                which is required by `&TestBasicStructWithDefaultValues: apache_avro::schema::AvroSchema`
                `&mut TestBasicStructWithDefaultValues: apache_avro::schema::derive::AvroSchemaComponent`
                which is required by `&mut TestBasicStructWithDefaultValues: apache_avro::schema::AvroSchema`
   note: the following trait must be implemented
       --> /home/martin/git/apache/avro/lang/rust/avro/src/schema.rs:1589:5
        |
   1589 | /     pub trait AvroSchemaComponent {
   1590 | |         fn get_schema_in_ctxt(named_schemas: &mut Names, enclosing_namespace: &Namespace)
   1591 | |             -> Schema;
   1592 | |     }
        | |_____^
   
   error[E0277]: the trait bound `TestBasicStructWithDefaultValues: apache_avro::schema::derive::AvroSchemaComponent` is not satisfied
       --> avro_derive/tests/derive.rs:1337:22
        |
   1337 |           serde_assert(TestBasicStructWithDefaultValues {
        |  _________------------_^
        | |         |
        | |         required by a bound introduced by this call
   1338 | |             a: 321,
   1339 | |             b: "A custom value for 'b'".to_owned(),
   1340 | |             condition: false,
   ...    |
   1347 | |             myenum: MyEnum::Bar,
   1348 | |         });
        | |_________^ the trait `apache_avro::schema::derive::AvroSchemaComponent` is not implemented for `TestBasicStructWithDefaultValues`
        |
        = note: required because of the requirements on the impl of `apache_avro::schema::AvroSchema` for `TestBasicStructWithDefaultValues`
   note: required by a bound in `serde_assert`
       --> avro_derive/tests/derive.rs:43:61
        |
   41   |     fn serde_assert<T>(obj: T)
        |        ------------ required by a bound in this
   42   |     where
   43   |         T: std::fmt::Debug + Serialize + DeserializeOwned + AvroSchema + Clone + PartialEq,
        |                                                             ^^^^^^^^^^ required by this bound in `serde_assert`
   
   error[E0283]: type annotations needed
       --> avro_derive/tests/derive.rs:1319:48
        |
   1319 |                     "array" => assert_eq!(Some(json!([1, 2, 3])), field.default),
        |                                                ^^^^^^^^^^^^^^^^ cannot infer type for type `{integer}`
        |
        = note: multiple `impl`s satisfying `{integer}: serde::Serialize` found in the `serde` crate:
                - impl serde::Serialize for i128;
                - impl serde::Serialize for i16;
                - impl serde::Serialize for i32;
                - impl serde::Serialize for i64;
                and 8 more
        = note: required because of the requirements on the impl of `serde::Serialize` for `&{integer}`
   note: required by a bound in `serde_json::to_value`
       --> /home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_json-1.0.79/src/value/mod.rs:944:8
        |
   944  |     T: Serialize,
        |        ^^^^^^^^^ required by this bound in `serde_json::to_value`
        = note: this error originates in the macro `json_internal` (in Nightly builds, run with -Z macro-backtrace for more info)
   
   error[E0283]: type annotations needed
       --> avro_derive/tests/derive.rs:1321:30
        |
   1321 |                           Some(json!({
        |  ______________________________^
   1322 | |                             "a": 1,
   1323 | |                             "b": 2
   1324 | |                         })),
        | |__________________________^ cannot infer type for type `{integer}`
        |
        = note: multiple `impl`s satisfying `{integer}: serde::Serialize` found in the `serde` crate:
                - impl serde::Serialize for i128;
                - impl serde::Serialize for i16;
                - impl serde::Serialize for i32;
                - impl serde::Serialize for i64;
                and 8 more
        = note: required because of the requirements on the impl of `serde::Serialize` for `&{integer}`
   note: required by a bound in `serde_json::to_value`
       --> /home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_json-1.0.79/src/value/mod.rs:944:8
        |
   944  |     T: Serialize,
        |        ^^^^^^^^^ required by this bound in `serde_json::to_value`
        = note: this error originates in the macro `json_internal` (in Nightly builds, run with -Z macro-backtrace for more info)
   
   Some errors have detailed explanations: E0277, E0283, E0599.
   For more information about an error, try `rustc --explain E0277`.
   error: could not compile `apache-avro-derive` due to 9 previous errors
   warning: build failed, waiting for other jobs to finish...
   error: build failed
   </pre>
   </details> 
   
   The first error is the expected one, but then it also logs a lot more that is not really helpful and is actually hiding the real problem.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org