{
  "format": "rpai-station-workflow",
  "version": 1,
  "name": "Error handling",
  "variables": [
    {
      "id": "var-folder",
      "name": "folder",
      "type": "string",
      "value": "~/Documents/Station Academy"
    }
  ],
  "activities": [
    {
      "id": "academy-001",
      "type": "comment",
      "name": "About this workflow",
      "properties": {
        "text": "Station Academy, Level 6. Tries to read a file that does not exist, catches the error, records it and carries on."
      }
    },
    {
      "id": "academy-002",
      "type": "file_operation",
      "name": "Make sure the practice folder exists",
      "properties": {
        "operation": "create_folder",
        "sourcePath": "{{folder}}"
      }
    },
    {
      "id": "academy-006",
      "type": "try_catch",
      "name": "Read a file that may be missing",
      "properties": {
        "catchAction": "continue",
        "errorVariable": "problem"
      },
      "tryBlock": [
        {
          "id": "academy-003",
          "type": "read_file",
          "name": "Read the missing file",
          "properties": {
            "filePath": "{{folder}}/does-not-exist.txt",
            "encoding": "utf-8",
            "saveToVariable": "content"
          }
        }
      ],
      "catchBlock": [
        {
          "id": "academy-004",
          "type": "log",
          "name": "Explain what happened",
          "properties": {
            "message": "Could not read the file: {{problem}}",
            "level": "warning"
          }
        },
        {
          "id": "academy-005",
          "type": "set_variable",
          "name": "Use a safe default",
          "properties": {
            "variableName": "content",
            "valueType": "static",
            "value": "(no file)"
          }
        }
      ]
    },
    {
      "id": "academy-007",
      "type": "log",
      "name": "Carry on",
      "properties": {
        "message": "Continuing with: {{content}}",
        "level": "info"
      }
    }
  ]
}
