sagiegurari / cargo-make

Rust task runner and build tool.
https://sagiegurari.github.io/cargo-make/
Apache License 2.0
2.56k stars 125 forks source link

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

Open wmmc88 opened 4 months ago

wmmc88 commented 4 months ago

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"
'''
sagiegurari commented 4 months ago

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

sagiegurari commented 4 months ago

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.