Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
S
stats-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
stats-facil
Validations
3433a3d3
Valider
3433a3d3
rédigé
11 years ago
par
Benaka Moorthi
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Finished converting exception handling.
parent
c6350fbb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
5
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
5 fichiers modifiés
core/Error.php
+8
-13
8 ajouts, 13 suppressions
core/Error.php
core/ExceptionHandler.php
+44
-23
44 ajouts, 23 suppressions
core/ExceptionHandler.php
core/Log.php
+0
-2
0 ajout, 2 suppressions
core/Log.php
core/Plugin.php
+15
-1
15 ajouts, 1 suppression
core/Plugin.php
index.php
+2
-1
2 ajouts, 1 suppression
index.php
avec
69 ajouts
et
40 suppressions
core/Error.php
+
8
−
13
Voir le fichier @
3433a3d3
...
@@ -139,11 +139,11 @@ class Error
...
@@ -139,11 +139,11 @@ class Error
public
static
function
setErrorHandler
()
public
static
function
setErrorHandler
()
{
{
Piwik_AddAction
(
'Log.formatFileMessage'
,
array
(
'Error'
,
'formatFileAndDBLogMessage'
));
Piwik_AddAction
(
'Log.formatFileMessage'
,
array
(
'
\\Piwik\\
Error'
,
'formatFileAndDBLogMessage'
));
Piwik_AddAction
(
'Log.formatDatabaseMessage'
,
array
(
'Error'
,
'formatFileAndDBLogMessage'
));
Piwik_AddAction
(
'Log.formatDatabaseMessage'
,
array
(
'
\\Piwik\\
Error'
,
'formatFileAndDBLogMessage'
));
Piwik_AddAction
(
'Log.formatScreenMessage'
,
array
(
'Error'
,
'formatScreenMessage'
));
Piwik_AddAction
(
'Log.formatScreenMessage'
,
array
(
'
\\Piwik\\
Error'
,
'formatScreenMessage'
));
set_error_handler
(
array
(
'Error'
,
'errorHandler'
));
set_error_handler
(
array
(
'
\\Piwik\\
Error'
,
'errorHandler'
));
}
}
public
static
function
errorHandler
(
$errno
,
$errstr
,
$errfile
,
$errline
)
public
static
function
errorHandler
(
$errno
,
$errstr
,
$errfile
,
$errline
)
...
@@ -153,7 +153,7 @@ class Error
...
@@ -153,7 +153,7 @@ class Error
return
;
return
;
}
}
$plugin
=
false
;
$plugin
=
'unknown'
;
$backtrace
=
''
;
$backtrace
=
''
;
$bt
=
@
debug_backtrace
();
$bt
=
@
debug_backtrace
();
...
@@ -166,18 +166,13 @@ class Error
...
@@ -166,18 +166,13 @@ class Error
.
'(...) called at ['
.
'(...) called at ['
.
(
isset
(
$debug
[
'file'
])
?
$debug
[
'file'
]
:
''
)
.
':'
.
(
isset
(
$debug
[
'file'
])
?
$debug
[
'file'
]
:
''
)
.
':'
.
(
isset
(
$debug
[
'line'
])
?
$debug
[
'line'
]
:
''
)
.
']'
.
"
\n
"
;
.
(
isset
(
$debug
[
'line'
])
?
$debug
[
'line'
]
:
''
)
.
']'
.
"
\n
"
;
// try and discern the plugin name
if
(
empty
(
$plugin
))
{
if
(
preg_match
(
"/^Piwik
\\
Plugins
\\
([a-z_]+)
\\
/"
,
$debug
[
'class'
],
$matches
))
{
$plugin
=
$matches
[
1
];
}
}
}
}
$plugin
=
Plugin
::
getPluginNameFromBacktrace
(
$bt
);
}
}
$error
=
new
Error
(
$errno
,
$errstr
,
$errfile
,
$errline
,
$backtrace
);
$error
=
new
Error
(
$errno
,
$errstr
,
$errfile
,
$errline
,
$backtrace
);
Log
::
e
(
$plugin
?:
'unknown'
,
$error
);
Log
::
e
(
$plugin
,
$error
);
switch
(
$errno
)
{
switch
(
$errno
)
{
case
E_ERROR
:
case
E_ERROR
:
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
core/ExceptionHandler.php
+
44
−
23
Voir le fichier @
3433a3d3
...
@@ -8,39 +8,60 @@
...
@@ -8,39 +8,60 @@
* @category Piwik
* @category Piwik
* @package Piwik
* @package Piwik
*/
*/
namespace
Piwik
;
use
Piwik\Common
;
use
Piwik\Piwik
;
use
Piwik\Piwik
;
use
Piwik\Plugin
;
use
Piwik\Log
;
use
Piwik\Log
;
use
Piwik\FrontController
;
use
Piwik\FrontController
;
use
Piwik\API\ResponseBuilder
;
/**
/**
* Exception handler used to display nicely exceptions in Piwik
* TODO
*
* @param Exception $exception
* @throws Exception
*/
*/
function
Piwik_
ExceptionHandler
(
Exception
$exception
)
class
ExceptionHandler
{
{
try
{
public
static
function
setUp
()
Log
::
e
(
"%s (%s): %s"
,
array
(
$exception
->
getFile
(),
$exception
->
getLine
(),
$exception
->
getMessage
()));
// TODO add backtrace?
{
}
catch
(
Exception
$e
)
{
Piwik_AddAction
(
'Log.formatFileMessage'
,
array
(
'\\Piwik\\ExceptionHandler'
,
'formatFileAndDBLogMessage'
));
if
(
FrontController
::
shouldRethrowException
())
{
Piwik_AddAction
(
'Log.formatDatabaseMessage'
,
array
(
'\\Piwik\\ExceptionHandler'
,
'formatFileAndDBLogMessage'
));
throw
$exception
;
Piwik_AddAction
(
'Log.formatScreenMessage'
,
array
(
'\\Piwik\\ExceptionHandler'
,
'formatScreenMessage'
));
set_exception_handler
(
array
(
'\\Piwik\\ExceptionHandler'
,
'exceptionHandler'
));
}
public
static
function
formatFileAndDBLogMessage
(
&
$message
,
$level
,
$pluginName
,
$datetime
,
$log
)
{
if
(
$message
instanceof
\Exception
)
{
$message
=
sprintf
(
"%s(%d): %s
\n
%s"
,
$message
->
getFile
(),
$message
->
getLine
(),
$message
->
getMessage
(),
$message
->
getTraceAsString
());
$message
=
$log
->
formatMessage
(
$level
,
$pluginName
,
$datetime
,
$message
);
}
}
}
// case when the exception is raised before the logger being ready
public
static
function
formatScreenMessage
(
&
$message
,
$level
,
$pluginName
,
$datetime
,
$log
)
// we handle the exception a la mano, but using the Logger formatting properties
{
$event
=
array
();
if
(
$message
instanceof
\Exception
)
{
$event
[
'errno'
]
=
$exception
->
getCode
();
if
(
!
Common
::
isPhpCliMode
())
{
$event
[
'message'
]
=
$exception
->
getMessage
();
@
header
(
'Content-Type: text/html; charset=utf-8'
);
$event
[
'errfile'
]
=
$exception
->
getFile
();
}
$event
[
'errline'
]
=
$exception
->
getLine
();
$event
[
'backtrace'
]
=
$exception
->
getTraceAsString
();
$formatter
=
new
ExceptionScreenFormatter
();
$outputFormat
=
strtolower
(
Common
::
getRequestVar
(
'format'
,
'html'
,
'string'
));
$response
=
new
ResponseBuilder
(
$outputFormat
);
$message
=
$response
->
getResponseException
(
new
\Exception
(
$message
->
getMessage
()));
}
}
$message
=
$formatter
->
format
(
$event
);
public
static
function
exceptionHandler
(
Exception
$exception
)
$message
.
=
"<br /><br />And this exception raised another exception
\"
"
.
$e
->
getMessage
()
.
"
\"
"
;
{
$plugin
=
Plugin
::
getPluginNameFromBacktrace
(
$exception
->
getTrace
());
Log
::
e
(
$plugin
,
$exception
);
Piwik
::
exitWithErrorMessage
(
$message
);
// TODO: what about this code?
/*if (FrontController::shouldRethrowException()) {
throw $exception;
}*/
}
}
}
}
\ No newline at end of file
Ce diff est replié.
Cliquez pour l'agrandir.
core/Log.php
+
0
−
2
Voir le fichier @
3433a3d3
...
@@ -155,8 +155,6 @@ class Log
...
@@ -155,8 +155,6 @@ class Log
private
function
createWriterByName
(
$writerName
)
private
function
createWriterByName
(
$writerName
)
{
{
$self
=
$this
;
$writer
=
false
;
$writer
=
false
;
if
(
$writerName
==
'file'
)
{
if
(
$writerName
==
'file'
)
{
$writer
=
array
(
$this
,
'logToFile'
);
$writer
=
array
(
$this
,
'logToFile'
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
core/Plugin.php
+
15
−
1
Voir le fichier @
3433a3d3
...
@@ -193,4 +193,18 @@ class Plugin
...
@@ -193,4 +193,18 @@ class Plugin
{
{
return
$this
->
pluginName
;
return
$this
->
pluginName
;
}
}
}
public
static
function
getPluginNameFromBacktrace
(
$backtrace
)
{
$plugin
=
false
;
foreach
(
$backtrace
as
$tracepoint
)
{
// try and discern the plugin name
if
(
empty
(
$plugin
))
{
if
(
preg_match
(
"/^Piwik
\\
Plugins
\\
([a-z_]+)
\\
/"
,
$tracepoint
[
'class'
],
$matches
))
{
$plugin
=
$matches
[
1
];
}
}
}
return
$plugin
?:
'unknown'
;
}
}
\ No newline at end of file
Ce diff est replié.
Cliquez pour l'agrandir.
index.php
+
2
−
1
Voir le fichier @
3433a3d3
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
use
Piwik\FrontController
;
use
Piwik\FrontController
;
use
Piwik\Error
;
use
Piwik\Error
;
use
Piwik\ExceptionHandler
;
define
(
'PIWIK_DOCUMENT_ROOT'
,
dirname
(
__FILE__
)
==
'/'
?
''
:
dirname
(
__FILE__
));
define
(
'PIWIK_DOCUMENT_ROOT'
,
dirname
(
__FILE__
)
==
'/'
?
''
:
dirname
(
__FILE__
));
if
(
file_exists
(
PIWIK_DOCUMENT_ROOT
.
'/bootstrap.php'
))
{
if
(
file_exists
(
PIWIK_DOCUMENT_ROOT
.
'/bootstrap.php'
))
{
...
@@ -44,7 +45,7 @@ if (!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) {
...
@@ -44,7 +45,7 @@ if (!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) {
Error
::
setErrorHandler
();
Error
::
setErrorHandler
();
require_once
PIWIK_INCLUDE_PATH
.
'/core/ExceptionHandler.php'
;
require_once
PIWIK_INCLUDE_PATH
.
'/core/ExceptionHandler.php'
;
set_exception_handler
(
'Piwik_
ExceptionHandler
'
);
ExceptionHandler
::
setUp
(
);
}
}
if
(
!
defined
(
'PIWIK_ENABLE_DISPATCH'
)
||
PIWIK_ENABLE_DISPATCH
)
{
if
(
!
defined
(
'PIWIK_ENABLE_DISPATCH'
)
||
PIWIK_ENABLE_DISPATCH
)
{
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter