cargo-make icon indicating copy to clipboard operation
cargo-make copied to clipboard

`cm_plugin_run_custom_task` will fail to run a task json if it contains `private` field

Open wmmc88 opened this issue 9 months ago • 2 comments

Describe The Bug

cm_plugin_run_custom_task will fail to run a task json if it contains private field. It looks like its because when parsing ${task.as_json}, json_parse will silently convert the boolean value to a string. This seems to happen regardless if I use --collection or not.

A workaround I'm currently using is having the plugin call unset taskjson.private, but im not sure what other boolean fields this issue could be affecting.

To Reproduce

Error Stack

cargo make --allow-private abc
[cargo-make] INFO - cargo make 0.37.12
[cargo-make] INFO - Calling cargo metadata to extract project info
[cargo-make] INFO - Cargo metadata done
[cargo-make] INFO - Project: sample-kmdf-driver
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: abc
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] ERROR - Error while running plugin: Source: Unknown Line: 8 - invalid type: string "true", expected a boolean at line 1 column 410
[cargo-make] WARN - Build Failed.

Code Sample

[plugins.impl.test-plugin]
script = '''
taskjson = json_parse ${task.as_json}
taskjson = json_encode taskjson

cm_plugin_run_custom_task ${taskjson}
'''

[tasks.abc]
private = true
plugin = "test-plugin"
script = '''
#!@duckscript

echo "Hello World"
'''

wmmc88 avatar May 15 '24 01:05 wmmc88

thanks for reporting will check. i wonder why numbers are ok but bools are not...

sagiegurari avatar May 15 '24 04:05 sagiegurari

confirmed its an issue. the actually fix it, i think i'll have to define a custom deserializer for any non string primitive field that knows to take original type and string type.

sagiegurari avatar May 17 '24 16:05 sagiegurari