← All procedures

core.catch

Execute a procedure with error handling

CLI
Package
@procedures/lib · README
Path
["core","catch"]
CLI
mark core catch --try <any>
As data
{"$proc":["core","catch"],"input":{}}
Tags
runs-refs

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/lib"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["core","catch"], { try: "<try>" });
console.log(JSON.stringify(result));

From the command line

$ mark core catch --try <any>

As data, in a program

{ "$proc": ["core", "catch"], "input": { "try": "<try>" } }

Input

FieldTypeRequiredDefaultDescription
tryanyyesProcedure ref to try executing. Should use $when: "catch" so it's not auto-executed during hydration. Example: ```json { "$proc": ["git", "commit"], "input": { "message": "auto" }, "$when": "catch" } ```
handleranynoHandler procedure ref called on error. Receives StepResultInfo (success, error, proc) merged with its input. Should return ContinueDecision { continue: boolean }.
cwdstringnoWorking directory for procedure execution

Output

FieldTypeRequiredDefaultDescription
successbooleanyesTrue when the try operand succeeded
resultanynoThe result of try, or the decision of the handler
errorstringnoThe error of try, when it failed
continuebooleanyesTrue when the caller can continue
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "try": {
        "description": "Procedure ref to try executing. Should use $when: \"catch\" so it's not auto-executed during hydration. Example: ```json { \"$proc\": [\"git\", \"commit\"], \"input\": { \"message\": \"auto\" }, \"$when\": \"catch\" } ```"
      },
      "handler": {
        "description": "Handler procedure ref called on error. Receives StepResultInfo (success, error, proc) merged with its input. Should return ContinueDecision { continue: boolean }."
      },
      "cwd": {
        "description": "Working directory for procedure execution",
        "type": "string"
      }
    },
    "required": [
      "try"
    ]
  },
  "output": {
    "type": "object",
    "properties": {
      "success": {
        "type": "boolean",
        "description": "True when the try operand succeeded"
      },
      "result": {
        "description": "The result of try, or the decision of the handler"
      },
      "error": {
        "description": "The error of try, when it failed",
        "type": "string"
      },
      "continue": {
        "type": "boolean",
        "description": "True when the caller can continue"
      }
    },
    "required": [
      "success",
      "continue"
    ],
    "additionalProperties": {}
  }
}