Skip to content

Troubleshooting

Common errors and debugging strategies.

Deployment Strategy

  1. Test Environment - Deploy with enabled: false
  2. Limited Scope - Start with specific patterns
  3. Monitoring - Watch logs for unexpected behavior
  4. Gradual Expansion - Slowly expand scope
  5. Production - Deploy fully tested only

Debugging

Comprehensive Logging

Use logging to debug issues:

javascript
function process(data) {
    Info("=== DEBUG START ===");
    Info("Kind: " + kind);
    Info("Name: " + name);
    Info("UUID: " + uuid);
    Info("Data keys: " + Object.keys(data).join(", "));

    if (data.process) {
        Info("Process PID: " + data.process.pid);
        Info("Process CMD: " + data.process.cmd);
    }

    DataSet("debug_test", "success");
    let retrieved = DataGet("debug_test");
    Info("DataSet test: " + retrieved);

    Info("=== DEBUG END ===");
}

Error Handling

Implement proper error checking:

javascript
function process(data) {
    try {
        let result = NetBlockIp();
        if (result !== 0) {
            Error("Failed to block IP: " + Errno());
        }

        let writeResult = WriteFile("/tmp/log.txt", "data");
        if (writeResult !== 0) {
            Error("Failed to write: " + Errno());
        }
    } catch (error) {
        Error("Reaction error: " + error.toString());
    }
}

Testing

Create test reactions with disabled state:

yaml
- kind: test_reaction
  name: my_test_reaction
  enabled: false
  version: 1.0
  breed: file_access
  mechanism: file_access
  importance: low

  bases:
    - dir: /tmp/test
      base: trigger.txt
  file_actions:
    - unlink

  reactions:
    - format: js
      code: |
        function process(data) {
          Info("=== TEST REACTION ===");

          DataSet("test", "success");
          let value = DataGet("test");
          Info("Test: " + (value === "success" ? "PASS" : "FAIL"));

          DataDelete("test");
          Info("=== TEST COMPLETE ===");
        }

Common Errors

Missing Required Fields

Error:

yaml
reactions:
  - format: js
    # Missing 'code' field

Fix:

yaml
reactions:
  - format: js
    code: |
      function process(data) {
        Info("Valid reaction");
      }

Invalid Format

Error:

yaml
reactions:
  - format: python
    code: |
      print("Not supported")

Fix:

yaml
reactions:
  - format: js  # Valid: js or shell only
    code: |
      function process(data) {
        Info("Valid format");
      }

Missing Process Function

Error:

yaml
reactions:
  - format: js
    code: |
      Info("This won't work");

Fix:

yaml
reactions:
  - format: js
    code: |
      function process(data) {
        Info("This will work");
      }

Network Helper Without netpolicy

Error:

javascript
function process(data) {
    NetBlockIp(); // Requires netpolicy feature
}

Fix: Enable netpolicy feature in configuration.