actions-rs / clippy-check

📎 GitHub Action for PR annotations with clippy warnings
https://github.com/marketplace/actions/rust-clippy-check
MIT License
289 stars 41 forks source link

JSON output failing to be parsed #29

Open jamiebrynes7 opened 4 years ago

jamiebrynes7 commented 4 years ago

I noticed on a PR (https://github.com/jamiebrynes7/spatialos-sdk-rs/pull/136) that GitHub actions was reporting that the Clippy step was failing, but no errors were being reported.

After turning on debug output, each clippy lint is followed by:

##[debug]Not a JSON, ignoring it

Example

This line originates from https://github.com/actions-rs/clippy-check/blob/master/src/check.ts#L70 where we attempt to parse each line of standard output as JSON.

Manually checking the JSON output from clippy, it seems to be valid.

Example JSON output (prettified) ```json { "reason": "compiler-message", "package_id": "spatialos-sdk 0.0.0 (path+file:///Users/runner/runners/2.161.0/work/spatialos-sdk-rs/spatialos-sdk-rs/spatialos-sdk)", "target": { "kind": ["lib"], "crate_types": ["lib"], "name": "spatialos-sdk", "src_path": "/Users/runner/runners/2.161.0/work/spatialos-sdk-rs/spatialos-sdk-rs/spatialos-sdk/src/lib.rs", "edition": "2018", "doctest": true }, "message": { "rendered": "error: transmute from a type (`f32`) to itself\n --> spatialos-sdk/src/worker/schema/primitives.rs:41:33\n |\n41 | Ok(unsafe { mem::transmute($schema_get(object.as_ptr(), field)) })\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n...\n86 | / impl_primitive_field!(\n87 | | f32,\n88 | | SchemaFloat,\n89 | | Schema_GetFloat,\n... |\n93 | | Schema_AddFloatList,\n94 | | );\n | |__- in this macro invocation\n |\n = note: `-D clippy::useless-transmute` implied by `-D warnings`\n = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_transmute\n\n", "children": [{ "children": [], "code": null, "level": "note", "message": "`-D clippy::useless-transmute` implied by `-D warnings`", "rendered": null, "spans": [] }, { "children": [], "code": null, "level": "help", "message": "for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_transmute", "rendered": null, "spans": [] }], "code": { "code": "clippy::useless_transmute", "explanation": null }, "level": "error", "message": "transmute from a type (`f32`) to itself", "spans": [{ "byte_end": 1794, "byte_start": 1743, "column_end": 84, "column_start": 33, "expansion": { "def_site_span": { "byte_end": 3377, "byte_start": 1191, "column_end": 2, "column_start": 1, "expansion": null, "file_name": "spatialos-sdk/src/worker/schema/primitives.rs", "is_primary": false, "label": null, "line_end": 84, "line_start": 23, "suggested_replacement": null, "suggestion_applicability": null, "text": [{ "highlight_end": 36, "highlight_start": 1, "text": "macro_rules! impl_primitive_field {" }, { "highlight_end": 6, "highlight_start": 1, "text": " (" }, { "highlight_end": 23, "highlight_start": 1, "text": " $rust_type:ty," }, { "highlight_end": 28, "highlight_start": 1, "text": " $schema_type:ident," }, { "highlight_end": 27, "highlight_start": 1, "text": " $schema_get:ident," }, { "highlight_end": 29, "highlight_start": 1, "text": " $schema_index:ident," }, { "highlight_end": 29, "highlight_start": 1, "text": " $schema_count:ident," }, { "highlight_end": 27, "highlight_start": 1, "text": " $schema_add:ident," }, { "highlight_end": 32, "highlight_start": 1, "text": " $schema_add_list:ident," }, { "highlight_end": 11, "highlight_start": 1, "text": " ) => {" }, { "highlight_end": 25, "highlight_start": 1, "text": " #[derive(Debug)]" }, { "highlight_end": 33, "highlight_start": 1, "text": " pub struct $schema_type;" }, { "highlight_end": 1, "highlight_start": 1, "text": "" }, { "highlight_end": 38, "highlight_start": 1, "text": " impl Field for $schema_type {" }, { "highlight_end": 40, "highlight_start": 1, "text": " type RustType = $rust_type;" }, { "highlight_end": 1, "highlight_start": 1, "text": "" }, { "highlight_end": 82, "highlight_start": 1, "text": " fn get(object: &SchemaObject, field: FieldId) -> Result<$rust_type> {" }, { "highlight_end": 52, "highlight_start": 1, "text": " if Self::count(object, field) > 0 {" }, { "highlight_end": 87, "highlight_start": 1, "text": " Ok(unsafe { mem::transmute($schema_get(object.as_ptr(), field)) })" }, { "highlight_end": 25, "highlight_start": 1, "text": " } else {" }, { "highlight_end": 56, "highlight_start": 1, "text": " Err(Error::missing_field::())" }, { "highlight_end": 18, "highlight_start": 1, "text": " }" }, { "highlight_end": 14, "highlight_start": 1, "text": " }" }, { "highlight_end": 1, "highlight_start": 1, "text": "" }, { "highlight_end": 98, "highlight_start": 1, "text": " fn index(object: &SchemaObject, field: FieldId, index: usize) -> Result<$rust_type> {" }, { "highlight_end": 56, "highlight_start": 1, "text": " let count = Self::count(object, field);" }, { "highlight_end": 35, "highlight_start": 1, "text": " if count > index {" }, { "highlight_end": 32, "highlight_start": 1, "text": " Ok(unsafe {" }, { "highlight_end": 92, "highlight_start": 1, "text": " mem::transmute($schema_index(object.as_ptr(), field, index as u32))" }, { "highlight_end": 23, "highlight_start": 1, "text": " })" }, { "highlight_end": 25, "highlight_start": 1, "text": " } else {" }, { "highlight_end": 74, "highlight_start": 1, "text": " Err(Error::index_out_of_bounds::(index, count))" }, { "highlight_end": 18, "highlight_start": 1, "text": " }" }, { "highlight_end": 14, "highlight_start": 1, "text": " }" }, { "highlight_end": 1, "highlight_start": 1, "text": "" }, { "highlight_end": 71, "highlight_start": 1, "text": " fn count(object: &SchemaObject, field: FieldId) -> usize {" }, { "highlight_end": 74, "highlight_start": 1, "text": " unsafe { $schema_count(object.as_ptr(), field) as usize }" }, { "highlight_end": 14, "highlight_start": 1, "text": " }" }, { "highlight_end": 1, "highlight_start": 1, "text": "" }, { "highlight_end": 84, "highlight_start": 1, "text": " fn add(object: &mut SchemaObject, field: FieldId, value: &$rust_type) {" }, { "highlight_end": 25, "highlight_start": 1, "text": " unsafe {" }, { "highlight_end": 85, "highlight_start": 1, "text": " $schema_add(object.as_ptr_mut(), field, mem::transmute(*value));" }, { "highlight_end": 18, "highlight_start": 1, "text": " }" }, { "highlight_end": 14, "highlight_start": 1, "text": " }" }, { "highlight_end": 1, "highlight_start": 1, "text": "" }, { "highlight_end": 91, "highlight_start": 1, "text": " fn add_list(object: &mut SchemaObject, field: FieldId, value: &[$rust_type]) {" }, { "highlight_end": 42, "highlight_start": 1, "text": " let ptr = value.as_ptr();" }, { "highlight_end": 32, "highlight_start": 1, "text": " let len = value" }, { "highlight_end": 27, "highlight_start": 1, "text": " .len()" }, { "highlight_end": 32, "highlight_start": 1, "text": " .try_into()" }, { "highlight_end": 68, "highlight_start": 1, "text": " .expect(\"Cannot work with a super long array\");" }, { "highlight_end": 25, "highlight_start": 1, "text": " unsafe {" }, { "highlight_end": 88, "highlight_start": 1, "text": " $schema_add_list(object.as_ptr_mut(), field, ptr as *const _, len);" }, { "highlight_end": 18, "highlight_start": 1, "text": " }" }, { "highlight_end": 14, "highlight_start": 1, "text": " }" }, { "highlight_end": 1, "highlight_start": 1, "text": "" }, { "highlight_end": 84, "highlight_start": 1, "text": " fn has_update(update: &SchemaComponentUpdate, field: FieldId) -> bool {" }, { "highlight_end": 56, "highlight_start": 1, "text": " Self::count(update.fields(), field) > 0" }, { "highlight_end": 14, "highlight_start": 1, "text": " }" }, { "highlight_end": 10, "highlight_start": 1, "text": " }" }, { "highlight_end": 7, "highlight_start": 1, "text": " };" }, { "highlight_end": 2, "highlight_start": 1, "text": "}" }] }, "macro_decl_name": "impl_primitive_field!", "span": { "byte_end": 3546, "byte_start": 3379, "column_end": 3, "column_start": 1, "expansion": null, "file_name": "spatialos-sdk/src/worker/schema/primitives.rs", "is_primary": false, "label": null, "line_end": 94, "line_start": 86, "suggested_replacement": null, "suggestion_applicability": null, "text": [{ "highlight_end": 23, "highlight_start": 1, "text": "impl_primitive_field!(" }, { "highlight_end": 9, "highlight_start": 1, "text": " f32," }, { "highlight_end": 17, "highlight_start": 1, "text": " SchemaFloat," }, { "highlight_end": 21, "highlight_start": 1, "text": " Schema_GetFloat," }, { "highlight_end": 23, "highlight_start": 1, "text": " Schema_IndexFloat," }, { "highlight_end": 26, "highlight_start": 1, "text": " Schema_GetFloatCount," }, { "highlight_end": 21, "highlight_start": 1, "text": " Schema_AddFloat," }, { "highlight_end": 25, "highlight_start": 1, "text": " Schema_AddFloatList," }, { "highlight_end": 3, "highlight_start": 1, "text": ");" }] } }, "file_name": "spatialos-sdk/src/worker/schema/primitives.rs", "is_primary": true, "label": null, "line_end": 41, "line_start": 41, "suggested_replacement": null, "suggestion_applicability": null, "text": [{ "highlight_end": 84, "highlight_start": 33, "text": " Ok(unsafe { mem::transmute($schema_get(object.as_ptr(), field)) })" }] }] } } ```

As far as I can tell, this JSON output matches the interfaces defined in https://github.com/actions-rs/clippy-check/blob/master/src/check.ts#L10

I'm not very familiar with Typescript or the semantics of JSON.parse and how @actions/exec (https://github.com/actions/toolkit/tree/master/packages/exec) pipes standard output through, so despite my best efforts I'm struggling to drill down to the root of this.

I'm using Rust 1.39.0 and the clippy action is running on the macOS-latest machine.

jamiebrynes7 commented 4 years ago

Some extra information, logging the error thrown by JSON.parse() (https://github.com/jamiebrynes7/clippy-check/commit/100d2c352ba28cfacff399198d057a7e8731a557#diff-5fa83cff45c4b6ef3a61b59b784d45e4R73) yields the following for seemingly each JSON parsing failure:

##[debug]SyntaxError: Unexpected token , in JSON at position 0

Example run