public function throwabeExtensions()
 {
     $t = new Throwable('Test');
     $this->assertNotEquals([], $t->getStackTrace());
     $t->clearStackTrace();
     $this->assertEquals([], $t->getStackTrace());
 }
Ejemplo n.º 2
0
 /**
  * Fills in stack trace information. 
  *
  * @param   self $from
  * @return  self this
  */
 public function fillInStackTrace($from = null)
 {
     static $except = ['call_user_func_array' => 1, 'call_user_func' => 1];
     // Error messages
     foreach (\xp::$errors as $file => $list) {
         $this->addStackTraceFor($file, null, null, null, [], $list);
     }
     foreach ($from ? $from->getTrace() : $this->getTrace() as $i => $trace) {
         if (!isset($trace['function']) || isset($except[$trace['function']]) || isset($trace['object']) && $trace['object'] instanceof self) {
             continue;
         }
         // Not all of these are always set: debug_backtrace() should
         // initialize these - at least - to NULL, IMO => Workaround.
         $this->addStackTraceFor($trace['file'] ?? null, $trace['class'] ?? null, $trace['function'] ?? null, $trace['line'] ?? null, $trace['args'] ?? null, [['' => 1]]);
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Handle exception from scriptlet
  *
  * @param   lang.Throwable t
  * @param   int status
  * @param   bool trace whether to show stacktrace
  * @return  scriptlet.HttpScriptletResponse
  */
 protected function fail(\lang\Throwable $t, $status, $trace)
 {
     $package = create(new \lang\XPClass(__CLASS__))->getPackage();
     $errorPage = $package->providesResource('error' . $status . '.html') ? $package->getResource('error' . $status . '.html') : $package->getResource('error500.html');
     $response = new \scriptlet\HttpScriptletResponse();
     $response->setStatus($status);
     $response->setContent(str_replace('<xp:value-of select="reason"/>', $trace ? $t->toString() : $t->getMessage(), $errorPage));
     return $response;
 }
Ejemplo n.º 4
0
 /**
  * Invoke a block, wrap PHP5 and PHP7 native base exceptions in lang.Error
  *
  * @param  function(?): void $block
  * @param  var $arg
  * @return void
  */
 private function invoke($block, $arg)
 {
     try {
         $block($arg);
     } catch (Throwable $e) {
         throw $e;
     } catch (\Exception $e) {
         throw Throwable::wrap($e);
     } catch (\Throwable $e) {
         throw Throwable::wrap($e);
     }
 }
Ejemplo n.º 5
0
 public function printStackTrace()
 {
     $out = new MemoryOutputStream();
     $e = new Throwable('Test');
     $e->printStackTrace(Streams::writeableFd($out));
     $this->assertEquals($e->toString(), $out->getBytes());
 }
 /**
  * Called when compilation fails
  *
  * @param   xp.compiler.io.Source src
  * @param   lang.Throwable reason
  */
 public function compilationFailed(Source $src, \lang\Throwable $reason)
 {
     $this->writer->writeLine($src, ': ', $reason->compoundMessage());
     $reason->printStackTrace();
 }
 /**
  * Called when compilation fails
  *
  * @param   xp.compiler.io.Source src
  * @param   lang.Throwable reason
  */
 public function compilationFailed(Source $src, \lang\Throwable $reason)
 {
     $this->writer->write('F');
     $this->failed++;
     $this->messages[$src->getURI()] = $reason->compoundMessage();
 }
Ejemplo n.º 8
0
 /**
  * Handle exception from scriptlet
  *
  * @param   scriptlet.Response $response
  * @param   lang.Throwable $t
  * @param   int $status
  * @param   bool $trace whether to show stacktrace
  * @return  scriptlet.HttpScriptletResponse
  */
 protected function error($response, \lang\Throwable $t, $status, $trace)
 {
     $package = $this->getClass()->getPackage();
     $errorPage = $package->getResource($package->providesResource('error' . $status . '.html') ? 'error' . $status . '.html' : 'error500.html');
     $response->setProcessed(false);
     $response->setStatus($status);
     $response->setContent(str_replace('<xp:value-of select="reason"/>', $trace ? $t->toString() : $t->getMessage(), $errorPage));
 }