Skip to Content
PluginsGuides

Call your plugin from a terminal

Run one of your plugin's RPC methods on the running engine with npx @conciv/cli plugin call, and read its JSON answer.

npx @conciv/cli plugin call runs one of your plugin's RPC methods on the running engine and prints the answer. Use it to try a method while you write it, or to call your plugin from a script.

Call a method

Start your dev server, then run the method from your project folder:

terminal
npx @conciv/cli plugin call plant-shelf count --data '{"plant": "fern"}'
output
{"ok": true, "data": {"plant": "fern", "count": 3}}

A few things to notice:

  • plant-shelf is the id of the plugin's RPC contract. count is the method. See Share an RPC method.
  • --data is the method's input, as JSON. Leave it out for a method that takes no input. -d is the short form.
  • The answer is one line of JSON. The command exits 0 on success.

The plugins conciv ships answer the same way. This reads the test runner's last result:

terminal
npx @conciv/cli plugin call test-runner status

Read a failure

A failure prints ok: false and an error. The command exits 1. A method's own error carries its name as type, with its message and data. Here the shelf has no ferns left:

terminal
npx @conciv/cli plugin call plant-shelf sell --data '{"plant": "fern"}'
output
{
  "ok": false,
  "error": {
    "kind": "user",
    "message": "fern is sold out",
    "code": "PLUGIN_RPC",
    "type": "sold-out",
    "data": {"plant": "fern"}
  }
}

The engine answers some errors itself:

  • rpc.unavailable: no plugin registered that contract id.
  • rpc.method_not_found: the contract has no such method.
  • rpc.invalid_input: the data does not match the method's input.
  • rpc.internal: the method threw. The code is PLUGIN_RPC_INTERNAL.
  • rpc.invalid_output: the method returned something its output schema refuses. The code is PLUGIN_RPC_INTERNAL.

The command refuses data that is not JSON before it sends anything:

output
{
  "ok": false,
  "error": {
    "kind": "user",
    "message": "--data is not JSON: {plant: fern}",
    "hint": "pass the method's input as JSON, for example --data '{}'"
  }
}

Next steps

On this page