plugin: type-check errors always report "parameter number 1"
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 70/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- backend, build-system
Research direction
Start with the EXTENSION_FUNCTION_CHECK_ITERATOR macro in source/plugin/include/plugin/plugin_interface.hpp (around line 76), where the index is stringified instead of printed. Then check the preprocessed load() in the cli_core_plugin source and the metacall_cli_core_plugin_test CMakeLists.txt, whose early return depends on the order of add_subdirectory calls in source/CMakeLists.txt. Done when the message names the wrong parameter's index, a test checks the second-parameter message, and the test actually runs under ctest.
Written by the indexing model from the issue text.
Description
🐛 Bug Report
When a plugin function gets an argument of the wrong type, the error message always says "The parameter number 1", whichever parameter was wrong.
Expected Behavior
The message names the parameter that has the wrong type, for example "The parameter number 2" when the second argument is wrong.
Current Behavior
Every type error says "The parameter number 1":
args[0] = 5 (Int) -> Failed to load a script. The parameter number 1 requires a value of type String, received: Int
args[1] = "x" (String) -> Failed to load a script. The parameter number 1 requires a value of type Array, received: String
EXTENSION_FUNCTION_CHECK_ITERATOR builds the message with this (plugin_interface.hpp#L76):
PREPROCESSOR_STRINGIFY(PREPROCESSOR_ARGS_COUNT(iterator))
iterator is the index that PREPROCESSOR_FOR passes in (0, 1, ...). PREPROCESSOR_ARGS_COUNT(iterator) counts how many macro arguments that is, which is always 1, instead of using its value. The preprocessed load() in cli_core_plugin.cpp shows it: both checks have the string "1".
Possible Solution
Print the index instead of counting it, starting from 1 like extension_function_check_array in cli_core_plugin.cpp already does ("#" << (i + 1)):
ss << error ". The parameter number " << ((iterator) + 1) << " requires a value of type " << ...
And add a test in metacall_cli_core_plugin_test that checks the message for the second parameter. I'd also fix the typo "argumens" in the argument count message of the same file, if that's OK.
Related problem I found while adding the test: metacall_cli_core_plugin_test is never built. Its CMakeLists.txt returns early with NOT TARGET cli_core_plugin, but source/CMakeLists.txt adds tests before cli, so that target doesn't exist yet when the check runs. Three more tests have the same check and are skipped too: metacall_cli_core_plugin_await_test, metacall_plugin_extension_destroy_order_test and metacall_plugin_extension_invalid_path_test (since 3a631c67 and 24db326a in 2024). None of them appear in the Linux CI logs (for example, the GCC debug job of the last develop run, 212 tests).
Moving add_subdirectory(cli) before add_subdirectory(tests) fixes it. Locally the skipped tests pass after that (the await test needs the Node port, which I didn't build), and the full ctest passes 111/111. Without it, the new test wouldn't run in CI. Should I include it in the same PR as a separate commit, or open a separate issue for it?
Steps to Reproduce
- Build with the CLI (
OPTION_BUILD_LOADERS_NODE=ON, which buildscli_core_plugin). - Load the plugin and call
loadwith a String as the second argument (it expects an Array). I used a String because MetaCall converts numbers to an Array before the call, so they never reach this check.
void *handle = NULL;
metacall_load_from_configuration(CLI_CORE_PLUGIN_PATH, &handle, allocator);
void *args[2] = { metacall_value_create_string("node", 4), metacall_value_create_string("x", 1) };
void *ret = metacallhv_s(handle, "load", args, 2);
struct metacall_exception_type ex;
metacall_error_from_value(ret, &ex);
printf("%s\n", ex.message); /* "... The parameter number 1 requires a value of type Array, received: String" */
- The message says parameter 1, but the wrong one is the second.
Context (Environment)
Found while working on #560. develop at 11e2b835, Ubuntu 24.04, GCC 13.3. It's in the macro, so every plugin that uses EXTENSION_FUNCTION_CHECK is affected (CLI core and sandbox plugins, sandbox plugin).
I already have the fix, the test and the CMake change working locally (the full ctest passes with GCC and Clang), and I'd like to open the PR for this myself. It touches the same header as #954, but different lines, and it applies cleanly on top of it. Can I go ahead?
- Dominant language
- C
- Stars
- 1.8k
- Forks
- 266
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 14
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from metacall/core
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
metacall/core#964 · 1 comment ·
Maintainers usually reply within 1 day
-
pre-push hook empties VERSION when the clone has no tagsPossibly taken @vedant21-oss claimed this 17 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
metacall/core#939 · 3 comments ·
Maintainers usually reply within 1 day
-
TOCTOU race condition vulnerability!Possibly taken @akshatchitransh claimed this 1 day ago. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
metacall/core#961 · 2 comments ·
Maintainers usually reply within 1 day
-
Go Port Race Conditions on MacOSPossibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
metacall/core#942 · 3 comments ·
Maintainers usually reply within 1 day
-
Stack buffer overflow in `metacall.c` — is the 16-argument limit intentional?Possibly taken @10vulture1005 claimed this 34 days ago. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 28/100
metacall/core#923 · 2 comments ·
Maintainers usually reply within 1 day
Similar issues
-
agent:WSL code-review linux pri:low refactoring tooling
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
DOC BUG Missing
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SDL-Hercules-390/hyperion#911 ·
Maintainers usually reply within 1 day
-
build: man page directory doubledPossibly taken @zeusgoose claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
esp-mosaico/esp-mosaico-bsp#40 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 62/100