Skip to content

PHP exception detector is too strict #2

@steren

Description

@steren

As we can read on https://github.com/GoogleCloudPlatform/fluent-plugin-detect-exceptions/blob/master/lib/fluent/plugin/exception_detector.rb

The rule to detect a PHP exception is:

      rule(:start_state, /PHP (?:Notice|Parse error|Fatal error|Warning):/,
           :php_stack_begin),
      rule(:php_stack_begin, /^Stack trace:/, :php_stack_frames),
      rule(:php_stack_frames, /^#\d/, :php_stack_frames),
      rule(:php_stack_frames, /^\s+thrown in /, :start_state)

This is too strict. It is indeed valid on App Engine standard, but on another environment, the exceptions are not formatted this way:

On my local machine, I run the following code:

<?php
function func1() {
  throw new Exception('Custom exception');
};
function func2() {
  func1();
};

try { 
  func2();
} catch (Exception $e) {
  print (string)$e;
}
?>

Here is the output:

exception 'Exception' with message 'Custom exception' in /Users/steren/work/test-php/test.php:5
Stack trace:
#0 /Users/steren/work/test-php/test.php(9): func1()
#1 /Users/steren/work/test-php/test.php(13): func2()
#2 {main}

As you see, it does not start with PHP Fatal Error and the last line is not thrown in

Because this plugin is intended to be used on Compute Engine, the PHP stacktrace detection should be compatible with the default way to print exception in PHP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions