silverstripe / silverstripe-raygun

Raygun.com integration for PHP
BSD 3-Clause "New" or "Revised" License
6 stars 23 forks source link

Add a task which triggers an exception #75

Open edwilde opened 1 month ago

edwilde commented 1 month ago

Description

This is standard practice in our raygun implementations, because it is really handy to have a /dev/task which can be triggered in deployed environments to simulate an exception - and confirm that Raygun handles it.

Additional context or points of discussion

The task is super-simple:

<?php

namespace App\Tasks;

use Exception;
use SilverStripe\Dev\BuildTask;

/**
 * Task used for testing Raygun error logging
 */
class ExceptionTask extends BuildTask
{
    /**
     * @inheritDoc
     */
    protected $title = 'Trigger an exception for Raygun';

    /**
     * @inheritDoc
     */
    private static $segment = 'ExceptionTask';

    /**
     * @inheritDoc
     */
    public function getDescription(): string
    {
        return 'A simple task that throws an Exception for Raygun to report';
    }

    /**
     * @inheritDoc
     */
    public function run(mixed $request): void
    {
        throw new Exception('Successful Exception!');
    }

}

Validations