0

A process into my plugin provoke a fatal error in Linux Server which I have not access, for example to define a WP_DEBUG_LOG.

I could identified the conflict in the event related to generate an jpeg image from a graph (jpgraph - CanvasGraph()).

What I'm looking for :

First, extract any-to-specific info from the server or wordpress, that I can see in the response (like the string wordpress tipically send "../article/debbugin-in-wordpress/">learn more about wordpress debbuging") to figure out whats the especific problem and how solve it.

And second, catch this error and prevent to evolve into fatal error.

What I tried :

I try to catch this fatal error in more than one way. But always fires first the wordpress "fatal error handler" crashing the view.

I try first with a custom try/catch block (It doesnt work), then with WP_Error like is_wp_error() and if/else blocks to throw new Excepion (It doesnt work), after try to handle this with the WP_Fatal_Error_Handler but I couldn't find any example so I'm reading the entire class (which works with try/catch blocks) to figure out something (examples of real use case are welcome).

Resume :

Problem

  1. I got a fatal error in my plugin (only with Linux Server)
  2. I try to catch it first with try/catch, then is_wp_error, both without success
  3. Wordpress triggers it fatal error handler always first
  4. I haven't any info

Goals:

  1. I looking to prevent the fatal error crash
  2. Get any-to-specific info from server (Linux, which I have not direct access e.g to define WP_DEBUG_LOG in wp-config.php) or wordpress about the error (my enviroment of action is just my plugin files, I can upload it & download it but nothing else)

This is my code : This chunk of code provoke a fatal error into Linux Server. I can't catch errors from the class neither the instance or Stroke method.

    try{

      $graph = new CanvasGraph( 330 , 100 );

      if ( is_wp_error( $graph ) ){ echo "graph is wp_error"; }

      if ( is_null( $graph ) ){ throw new Exception( "page4 technical_data : graph is_null  |  " ); var_dump( $graph ); }
      if ( !isset( $graph ) ){ throw new Exception( "page4 technical_data : graph is_not_set  |  " ); var_dump( $graph ); }
      if ( empty( $graph ) ){ throw new Exception( "page4 technical_data : graph is_empty  |  " ); var_dump( $graph ); }

      $data = array(
        array( utf8_decode( "technical data" ), utf8_decode( "Technical Data" ) ),
        array( utf8_decode( "ecommerce" ), $ecommerce  ),
        array( utf8_decode( "values" ), $values  ),
        array( utf8_decode( "years" ), utf8_decode( "0.0 years" )  )
      );

      if ( $graph ){

        try{
          $table = new GTextTable();
          if ( is_null( $table ) ){ throw new Exception( "page4 technical_data : table is_null  |  " ); var_dump( $table ); }
          if ( !isset( $table ) ){ throw new Exception( "page4 technical_data : table is_not_set  |  " ); var_dump( $table ); }
          if ( empty( $table ) ){ throw new Exception( "page4 technical_data : table is_empty  |  " ); var_dump( $table ); }

          if ( $table ){

            $table->Set( $data );

            // Merge all cells in row 0
            $table->MergeRow( 0 );

            // Setup font and color
            $table->SetRowFont( 0, FF_ARIAL, FS_NORMAL, 4 );
            $table->SetFont( FF_ARIAL, FS_NORMAL, 10 );
            $table->SetRowColor( 0, 'gray2' );
            $table->SetCellFillColor( 1 , 0 , 'lightblue@' );
            $table->SetCellFillColor( 2 , 0 , 'lightblue@' );
            $table->SetCellFillColor( 3 , 0 , 'lightblue@' );
            $table->SetCellAlign( 0 , 0 , "left" );

            // Add table to the graph
            $graph->Add($table);
            $graph->img->SetMargin( 20, 15, 20, 10 );

            // Display the graph
            $graph->img->SetImgFormat('JPEG');
            $graph->img->SetQuality(100);
            $graph->img->SetAntiAliasing();

            try{

              $set_image_name = WP_MYPLUGIN_PATH . "jpgraph/temp/img_graph" . rand( 0,10000 ) . ".jpeg";
              $pg_imag = $graph->Stroke( $set_image_name );                
              if ( is_null( $pg_imag ) ){ throw new Exception( "page4 pg_imag : pg_imag is_null  |  " ); var_dump( $table ); }
              if ( !isset( $pg_imag ) ){ throw new Exception( "page4 pg_imag : pg_imag is_not_set  |  " ); var_dump( $table ); }
              if ( empty( $pg_imag ) ){ throw new Exception( "page4 pg_imag : pg_imag is_empty  |  " ); var_dump( $table ); }

              if ( $pg_imag ){

                // Set position
                $val_x = 20; $real_scale = 90;
                $old_yaxis = $pdf->GetY(); $val_y = $old_yaxis;
                $pdf->Image( $set_image_name, $val_x, $val_y, $real_scale );

              }

            }
            catch ( Exception $error ){ echo "  - MY ERROR -| page4 [ image_stroke ] : " . $error->getMessage() . " (.end.) "; }

          }

        }
        catch ( Exception $error ){ echo "  - MY ERROR -| page4 [ technical_data ] : " . $error->getMessage() . " (.end.) "; }

      }

    }
    catch ( Exception $error ){ echo "  -init message-| MY ERROR : " . $error->getMessage() . " (.end.) "; }
  • Is this thread of any help to you? You need to differentiate between fatal errors and exceptions and check which PHP version is run (since PHP7, you should be able to catch errors as well as exceptions) – kero Feb 10 at 13:38
  • I read the post @kero, that thread not work: the wordpress error handler triggers first than mine. So at the point at the error wordpress collapse and send by JSON that there was a fatal error. Thank for your time anyway nice.week.init(); :) – Zyncho Feb 10 at 14:02
  • You may try this plugin wordpress.org/plugins/wp-debugging, use it to enable DEBUG_LOG and also disable fatal error handler. – Vitauts Stočka Feb 10 at 16:19
  • I haven't access to admin! – Zyncho Feb 10 at 17:02
  • If you haven't already, please do ask for access rather than trying to fight against this. If they won't give you a login to the server or the admin site then at least the error logs from the server and details of the actual exception that's getting thrown. Or ideally a clone of the server as a VM where you can reproduce the problem with real data. Presumably this server belongs to your customer or employer, so make the case that's more efficient for them in terms of getting a fix cheaply / quickly if they help you. – Rup Feb 10 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.