Skip to content

Commit

Permalink
Defining new constants to replace hardcoded strings
Browse files Browse the repository at this point in the history
DISPLAY_ERROR_HALT   = 'halt'
DISPLAY_ERROR_INLINE = 'inline'
DISPLAY_ERROR_NONE   = 'none'

Fixes #16062
  • Loading branch information
dregad committed Jun 15, 2013
1 parent 5b44912 commit a01f234
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 39 deletions.
2 changes: 1 addition & 1 deletion admin/check/check_config_inc.php
Expand Up @@ -56,7 +56,7 @@
);

check_print_test_warn_row( 'MantisBT Application Errors should halt execution',
$g_display_errors[E_USER_ERROR] == 'halt',
$g_display_errors[E_USER_ERROR] == DISPLAY_ERROR_HALT,
array( false => 'Continuing after an error may lead to system and/or data integrity issues. Set $g_display_errors[E_USER_ERROR] = \'halt\';' )
);

Expand Down
39 changes: 21 additions & 18 deletions config_defaults_inc.php
Expand Up @@ -4089,38 +4089,41 @@
/**
* Errors Display method
* Defines what errors are displayed and how. Available options are:
* - 'halt' stop and display error message (including variables and
* backtrace if {@link $g_show_detailed_errors} is ON)
* - 'inline' display 1 line error and continue execution
* - 'none' no error displayed
* - DISPLAY_ERROR_HALT stop and display error message (including
* variables and backtrace if
* {@link $g_show_detailed_errors} is ON)
* - DISPLAY_ERROR_INLINE display 1 line error and continue execution
* - DISPLAY_ERROR_NONE no error displayed
*
* WARNING: E_USER_ERROR should always be set to 'halt'. Using another value
* will cause program execution to continue, which may lead to data integrity
* issues and/or cause MantisBT to function incorrectly.
* WARNING: E_USER_ERROR should always be set to DISPLAY_ERROR_HALT. Using
* another value will cause program execution to continue, which may lead to
* data integrity issues and/or cause MantisBT to function incorrectly.
*
* A developer might set this in config_inc.php as:
* $g_display_errors = array(
* E_WARNING => 'halt',
* E_NOTICE => 'inline',
* E_USER_ERROR => 'halt',
* E_USER_WARNING => 'inline',
* E_USER_NOTICE => 'inline'
* E_WARNING => DISPLAY_ERROR_HALT,
* E_NOTICE => DISPLAY_ERROR_INLINE,
* E_USER_ERROR => DISPLAY_ERROR_HALT,
* E_USER_WARNING => DISPLAY_ERROR_INLINE,
* E_USER_NOTICE => DISPLAY_ERROR_INLINE
* );
*
* @global array $g_display_errors
*/
$g_display_errors = array(
E_WARNING => 'inline',
E_NOTICE => 'none',
E_USER_ERROR => 'halt',
E_USER_WARNING => 'inline',
E_USER_NOTICE => 'none'
E_WARNING => DISPLAY_ERROR_INLINE,
E_NOTICE => DISPLAY_ERROR_NONE,
E_USER_ERROR => DISPLAY_ERROR_HALT,
E_USER_WARNING => DISPLAY_ERROR_INLINE,
E_USER_NOTICE => DISPLAY_ERROR_NONE
);

/**
* Detailed error messages
* Shows a list of variables and their values when an error is triggered.
* Only applies to error types configured to 'halt' in {@link $g_display_errors}
* Only applies to error types configured to DISPLAY_ERROR_HALT in
* {@link $g_display_errors}
*
* WARNING: Potential security hazard. Only turn this on when you really
* need it for debugging
*
Expand Down
5 changes: 5 additions & 0 deletions core/constant_inc.php
Expand Up @@ -498,6 +498,11 @@
define( 'CUSTOM_FIELD_TYPE_PROJECT', 3 );
define( 'CUSTOM_FIELD_TYPE_FILE', 4 );

# display types for $g_display_errors
define( 'DISPLAY_ERROR_HALT', 'halt' );
define( 'DISPLAY_ERROR_INLINE', 'inline' );
define( 'DISPLAY_ERROR_NONE', 'none' );

# system logging
# The logging levels can be combined using bitwise operators
define( 'LOG_ALL', ~0 ); # All possible log levels
Expand Down
6 changes: 3 additions & 3 deletions core/error_api.php
Expand Up @@ -124,7 +124,7 @@ function error_handler( $p_type, $p_error, $p_file, $p_line, $p_context ) {
case E_USER_ERROR:
$t_error_type = "APPLICATION ERROR #$p_error";
$t_error_description = error_string( $p_error );
if( $t_method == 'inline' ) {
if( $t_method == DISPLAY_ERROR_INLINE ) {
$t_error_description .= "\n" . error_string( ERROR_DISPLAY_USER_ERROR_INLINE );
}
break;
Expand All @@ -148,7 +148,7 @@ function error_handler( $p_type, $p_error, $p_file, $p_line, $p_context ) {
$t_error_description = nl2br( $t_error_description );

switch( $t_method ) {
case 'halt':
case DISPLAY_ERROR_HALT:
# disable any further event callbacks
if ( function_exists( 'event_clear_callbacks' ) ) {
event_clear_callbacks();
Expand Down Expand Up @@ -234,7 +234,7 @@ function error_handler( $p_type, $p_error, $p_file, $p_line, $p_context ) {
echo '</body></html>', "\n";
}
exit();
case 'inline':
case DISPLAY_ERROR_INLINE:
echo '<div class="error-inline">', $t_error_type, ': ', $t_error_description, '</div>';
$g_error_handled = true;
break;
Expand Down
32 changes: 17 additions & 15 deletions docbook/Admin_Guide/en-US/Configuration.xml
Expand Up @@ -3511,7 +3511,7 @@ $g_main_menu_custom_options = array(

<variablelist>
<varlistentry>
<term>halt</term>
<term>DISPLAY_ERROR_HALT</term>
<listitem>
<para>stop and display error message
(including variables and backtrace if
Expand All @@ -3521,15 +3521,15 @@ $g_main_menu_custom_options = array(
</listitem>
</varlistentry>
<varlistentry>
<term>inline</term>
<term>DISPLAY_ERROR_INLINE</term>
<listitem>
<para>display 1 line error and continue
execution
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>none</term>
<term>DISPLAY_ERROR_NONE</term>
<listitem>
<para>no error displayed</para>
</listitem>
Expand All @@ -3539,27 +3539,28 @@ $g_main_menu_custom_options = array(
<para>Default is</para>
<programlisting>
$g_display_errors = array(
E_WARNING => 'inline',
E_NOTICE => 'none',
E_USER_ERROR => 'halt',
E_USER_WARNING => 'inline',
E_USER_NOTICE => 'none'
E_WARNING => DISPLAY_ERROR_INLINE,
E_NOTICE => DISPLAY_ERROR_NONE,
E_USER_ERROR => DISPLAY_ERROR_HALT,
E_USER_WARNING => DISPLAY_ERROR_INLINE,
E_USER_NOTICE => DISPLAY_ERROR_NONE
);
</programlisting>
<para>A developer might set this in their
<filename>config_inc.php</filename> as:
<programlisting>
$g_display_errors = array(
E_WARNING => 'halt',
E_NOTICE => 'inline',
E_USER_ERROR => 'halt',
E_USER_WARNING => 'inline',
E_USER_NOTICE => 'inline'
E_WARNING => DISPLAY_ERROR_HALT,
E_NOTICE => DISPLAY_ERROR_INLINE,
E_USER_ERROR => DISPLAY_ERROR_HALT,
E_USER_WARNING => DISPLAY_ERROR_INLINE,
E_USER_NOTICE => DISPLAY_ERROR_INLINE
);
</programlisting>
</para>
<warning><para><emphasis>E_USER_ERROR</emphasis>
should always be set to <literal>'halt'</literal>.
should always be set to
<literal>DISPLAY_ERROR_HALT</literal>.
Using any other value will cause program execution
to continue despite the error, which may lead to data
integrity issues and/or cause MantisBT to function
Expand All @@ -3573,7 +3574,8 @@ $g_display_errors = array(
<listitem>
<para>Shows a list of variables and their values
whenever an error is triggered.
Only applies to error types configured to 'halt'
Only applies to error types configured to
<literal>DISPLAY_ERROR_HALT</literal>
in <emphasis>$g_display_errors</emphasis>.
</para>
<para>Default is OFF.</para>
Expand Down
8 changes: 6 additions & 2 deletions login_page.php
Expand Up @@ -228,8 +228,12 @@ function debug_setting_message ( $p_type, $p_setting, $p_value ) {
$t_warnings[] = debug_setting_message( 'security', $t_config, 'OFF' );
}
$t_config = 'display_errors';
if( config_get_global( $t_config )[E_USER_ERROR] != 'halt' ) {
$t_warnings[] = debug_setting_message( 'integrity', $t_config . '[E_USER_ERROR]', 'halt' );
if( config_get_global( $t_config )[E_USER_ERROR] != DISPLAY_ERROR_HALT ) {
$t_warnings[] = debug_setting_message(
'integrity',
$t_config . '[E_USER_ERROR]',
DISPLAY_ERROR_HALT
);
}
$t_debug_email = config_get( 'debug_email' );
if( $t_debug_email !== OFF ) {
Expand Down

0 comments on commit a01f234

Please sign in to comment.