Sign up to create your own snipts, or login.

Public snipts » error The latest public error snipts.

showing 1-13 of 13 snipts for error
  • getting rid of foreach error
    <?php
    // double any value whose key starts with 'b'
    $arr = array('a'=>1, 'b1'=>2, 'b2'=>3, 'c'=>4, 'd'=>5);
    $non_array = null;
    
    // Normal usage with an array
    print "Test 1:\n";
    foreach ($arr as $key => $val) {
        print "Key $key, Value $val\n";
    
    }
    
    // Normal usage with a non-array (undefined or otherwise empty data set)
    // Outputs: Warning: Invalid argument supplied for foreach() in test.php on line 16
    print "Test 2:\n";
    foreach ($non_array as $key => $val) {
        print "Key $key, Value $val\n";
    }
    
    // By casting the $non_array to an (array) type, it will function without error, skipping the loop
    print "Test 3:\n";
    foreach ((array) $non_array as $key => $val) {
        print "Key $key, Value $val\n";
    }
    
    print "Done.\n";
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by d13t on Feb 22, 2010 at 4:39 a.m. EST
  • Log errors in diffent folders/files reflecting the application folder structure.
    <?php
    /**
     * Log PHP's error into separate files. Recommended for use in production site.
     * Should be used in set_error_handler() to handle certain PHP errors (i.e. E_STRICT).
     * @link http://www.php.net/manual/en/function.set-error-handler.php Reference
     */
    function errorHandler($errno, $errstr, $errfile=NULL, $errline=NULL, $errcontext=NULL) {
      // Log uncategorized errors
      if (is_null($errfile)) {
        $errfile = 'errors.log';
      }
    
      // Reconstruct the path
      // define('APP_DIR', '/my/application/')
      // define('LOG_DIR', '/log_dir/')
      // E.g. /my/application/controller/index.php -> /log_dir/controller/index.php
      $pos = strpos($errfile, APP_DIR);
      if ($pos !== FALSE) {
        // Strip off the application directory and attach log directory
        $errfile = LOG_DIR.substr($errfile, $pos + strlen(CMS_ROOT));
      }
      else {
        $errfile = LOG_DIR.$errfile; // E.g. /log_dir/errors.log
      }
      $dir = dirname($errfile);
      // Create dir if necessary
      if (! file_exists($dir)) {
        mkdir($dir, 0775, TRUE);
      }
      
      $logFile = fopen($errfile, 'a');
      fwrite($logFile, date('Y-m-d H:i:s ').$errstr);
      if ($errline) fwrite($logFile, " on line $errline");
      fwrite($logFile, "\n");
      fclose($logFile);
      
      if (PRODUCTION_SITE) // Prevent err msg from being printed out (log errors silently)
        return TRUE;
    
      return FALSE;
    }
    ?>
    

    copy | embed

    0 comments - tagged in  posted by hongster on Jan 21, 2010 at 2:46 a.m. EST
  • htacccess php error reporting
    #php_flag display_errors on 
    #php_value error_reporting 2048
    

    copy | embed

    0 comments - tagged in  posted by malkir on Nov 19, 2009 at 8:18 p.m. EST
  • Log file error histogram analysis
    #!/usr/bin/python
    
    # Useful spotting patterns in errors logged to files. Intended to be used 
    # on rolled log files where the filename contains the date or some other 
    # unique index or sequence.
    #
    # Example:
    #  foo-2009-04-23.log
    #  foo-2009-04-24.log
    #  foo-2009-04-25.log
    #
    # Use grep to generate the input for this script. Use a pattern which will 
    # match a variety of possible events. This works best when only one such 
    # event is reported per line.
    #
    # Use the '-o' flag to output only the matched section:
    #
    # > grep -o "\b\w*Exception\b" *
    #
    #   foo-2009-04-23.log:RuntimeException
    #   foo-2009-04-23.log:IOException
    #   foo-2009-04-23.log:IOException
    #   foo-2009-04-23.log:IOException
    #   foo-2009-04-24.log:FileNotFoundException
    #   foo-2009-04-24.log:IOException
    #   foo-2009-04-25.log:OutOfMemoryException
    #
    # Pipe this output to this script and you will get cross-referenced 
    # histograms of:
    #
    # By input file (date):
    #   Count for each error type
    #
    # By Error type:
    #   Count for each day of ocurrence
    #
    # Number of errors (per file/date) - descending order
    #
    # Number of errors (per error type) - descending order
    
    
    import sys
    from math import log
    
    date_exception = dict()
    exception_date = dict()
    exception_all = dict()
    date_all = dict()
    
    def splitlines():
        input = sys.stdin.readlines()
        
        for line in input:
            (date, exception) = line.strip().split(":")
    
            if (not date_all.has_key(date)):
                date_all[date] = 0
            
            date_all[date] += 1
            
            if (not exception_all.has_key(exception)):
                exception_all[exception] = 0
                
            exception_all[exception] += 1
            
            if (not date_exception.has_key(date)):
                date_exception[date] = dict()
    
            count_map = date_exception[date]
    
            if (not count_map.has_key(exception)):
                count_map[exception] = 0
    
            count_map[exception] += 1
    
            if (not exception_date.has_key(exception)):
                exception_date[exception] = dict()
    
            count_map = exception_date[exception]
    
            if (not count_map.has_key(date)):
                count_map[date] = 0
    
            count_map[date] += 1
    
    def print_bar(prefix, label, value):
        print prefix + "%-30s (%5d) %s" % (label, value, "#" * int(log(value+1)*3))
    
    if __name__ == '__main__':
        splitlines()
        
        print "\n"
        for k in date_exception.keys():
            d = date_exception[k]
            print k
            
            l = sorted(d.iteritems(), key=lambda (k,v): (v,k), reverse=True)
            for item in l:
                print_bar("    ", item[0], item[1])
                
        print "\n"        
        for k in exception_date.keys():
            d = exception_date[k]
            print k
            
            l = sorted(d.iteritems(), key=lambda (k,v): (v,k), reverse=True)
            for item in l:
                print_bar("    ", item[0], item[1])
    
        print "\n"
        for s in sorted(exception_all.iteritems(), key=lambda (k,v): (v,k), reverse=True):
            print_bar("", s[0], s[1])
    
        print "\n"
        for s in sorted(date_all.iteritems(), key=lambda (k,v): (v,k), reverse=True):
            print_bar("", s[0], s[1])
    
            
    

    copy | embed

    0 comments - tagged in  posted by tweakt on Oct 08, 2009 at 6:23 p.m. EDT
  • php error checking
    <?
    
    // ==============
    // error checking
    // ==============
    if ($xmlFile === false) die('1');
    
    // max char length
    if (isset($xmlFile{201})) die('File name too long');
    
    // regex check for chars, numbers, periods, dash, and underscores only
    // also make sure there isn't 2 or more period next to each other.
    if (preg_match("/[^A-Za-z0-9_.\-]/", $xmlFile) || 
        preg_match("/[.]{2,}/", $xmlFile))
          die('2');
    
    // check if extension is xml
    if (!preg_match("/[.]xml$/", $xmlFile)) 
        die('3');
    
    // check if file exist
    if (!file_exists($_SERVER['DOCUMENT_ROOT']."/blah/$xmlFile"))
        die('File does not exist.');
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Sep 10, 2009 at 8:30 p.m. EDT
  • Forzar errores
    <?php ini_set ("display_errors","1" ) ?>
    

    copy | embed

    0 comments - tagged in  posted by rmondragon on Sep 08, 2009 at 5:48 p.m. EDT
  • Simple CSS error messages with as little html markup as possible.
    <!-- Use as shown below. Assumes the use of any 16x16 icons. Larger or smaller may have to adjust line-height and padding. Markup is half the size of my old version, which used nested tags to dictate padding necessary for bg images.
    
    Feel free to remove redundant selectors. They are present to ensure this will work stand-alone. -->
    
    <style type="text/css">
    	.error, .confirm {
    		font: normal normal 300 13px/16px Arial, Helvetica, sans-serif;
    		margin: 10px 0;
    		padding: 5px;
    		text-indent: 25px;
    		-moz-border-radius: 3px;
    		-webkit-border-radius: 3px;
    		border-radius: 3px;
    	}
    	.error {
    		background: #FEF1EC url(../assets/images/exclamation_frame.png) no-repeat 8px 5px;
    		border: 1px solid #CD0A0A;
    		color: #CD0A0A;
    	}
    	.confirm {
    		background: #D8FFD3 url(../assets/images/tick_circle_frame.png) no-repeat 8px 5px;
    		border: 1px solid #337C2A;
    		color: #337C2A;
    	}
    </style>
    	
    <p class="error">Some error!</p>
    <p class="confirm">Some confirmation!</p>
    

    copy | embed

    0 comments - tagged in  posted by cmoist on Aug 13, 2009 at 4:02 p.m. EDT
  • Ultimate Error Reporting For GCC
    -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align \
    -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations \
    -Wredundant-decls -Wnested-externs -Winline -Wno-long-long \
    -Wconversion -Wstrict-prototypes
    

    copy | embed

    0 comments - tagged in  posted by JoeBiellik on Feb 26, 2009 at 3:16 p.m. EST
  • Disable Error Reporting
    <?php
    error_reporting(0);
    ?>
    

    copy | embed

    0 comments - tagged in  posted by JoeBiellik on Feb 16, 2009 at 10:42 a.m. EST
  • zope3 application system error
    A system error has occurred.
    

    copy | embed

    0 comments - tagged in  posted by nick on Feb 04, 2009 at 10:49 p.m. EST
  • Simple Clearing of floats
    <div id="outer">  
             <div id="inner"> <h2>A Column</h2> </div>  
             <h1>Main Content</h1>  
             <p>Lorem ipsum</p>  
    </div>  
    
    #inner{  
       width:26%;  
       float:left;  
       }
      
    #outer{  
       width:100%;
       overflow:auto  
       }  
    

    copy | embed

    0 comments - tagged in  posted by YamilG on Feb 03, 2009 at 1:57 p.m. EST
  • ERROR: x11-plugins/compiz-plugins-freewins-9999 failed.
    >>> Verifying ebuild manifests
    
    >>> Emerging (1 of 1) x11-plugins/compiz-plugins-freewins-9999 from desktop-effects
     * checking ebuild checksums ;-) ...                                                                                                                                                                      [ ok ]
     * checking auxfile checksums ;-) ...                                                                                                                                                                     [ ok ]
     * checking miscfile checksums ;-) ...                                                                                                                                                                    [ ok ]
    >>> Unpacking source...
     * git update start -->
     *    repository: git://anongit.compiz-fusion.org/users/warlock/freewins
     *    local clone: /usr/portage/distfiles/git-src/compiz-plugins-freewins
     *    committish: master
    >>> Unpacked to /var/tmp/portage/x11-plugins/compiz-plugins-freewins-9999/work/freewins
    >>> Source unpacked in /var/tmp/portage/x11-plugins/compiz-plugins-freewins-9999/work
    >>> Compiling source in /var/tmp/portage/x11-plugins/compiz-plugins-freewins-9999/work/freewins ...
    make -s -j3 
    convert   : freewins.xml.in -> build/freewins.xml
    bcop'ing  : build/freewins.xml -> build/freewins_options.hbcop'ing  : build/freewins.xml -> build/freewins_options.h
    bcop'ing  : build/freewins.xml -> build/freewins_options.cc -> build/action.lo
    compiling : freewins.c -> build/freewins.lolibtool: compile: unable to infer tagged configuration
    libtool: compile: specify a tag with `--tag'
    make: *** [build/events.lo] Fehler 1
    make: *** Warte auf noch nicht beendete Prozesse...
    libtool: compile: unable to infer tagged configuration
    libtool: compile: specify a tag with `--tag'
    make: *** [build/action.lo] Fehler 1
    libtool: compile: unable to infer tagged configuration
    libtool: compile: specify a tag with `--tag'
    make: *** [build/freewins.lo] Fehler 1
     * 
     * ERROR: x11-plugins/compiz-plugins-freewins-9999 failed.
     * Call stack:
     *               ebuild.sh, line   49:  Called src_compile
     *             environment, line 2555:  Called die
     * The specific snippet of code:
     *       emake || die "emake failed"
     *  The die message:
     *   emake failed
     * 
     * If you need support, post the topmost build error, and the call stack if relevant.
     * A complete build log is located at '/var/lib/entropy/logs/x11-plugins:compiz-plugins-freewins-9999:20090128-204924.log'.
     * The ebuild environment file is located at '/var/tmp/portage/x11-plugins/compiz-plugins-freewins-9999/temp/environment'.
     * This ebuild is from an overlay named 'desktop-effects': '/usr/local/portage/layman/desktop-effects/'
     * 
    
    >>> Failed to emerge x11-plugins/compiz-plugins-freewins-9999, Log file:
    
    >>>  '/var/lib/entropy/logs/x11-plugins:compiz-plugins-freewins-9999:20090128-204924.log'
    

    copy | embed

    0 comments - tagged in  posted by berot3 on Jan 28, 2009 at 3:19 p.m. EST
  • Php debug
    <?php
    $debug = true;// false for live website
    $contact_email  =  "";
    
    # **************************** #
    # ***** ERROR MANAGEMENT ***** #
    // Create the error handler.
    function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {
    
    	global $debug, $contact_email;
    	
    	// Build the error message.
    	$message = "An error occurred in script '$e_file' on line $e_line: \n<br />$e_message\n<br />";
    	
    	// Add the date and time.
    	$message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />";
    	
    	// Append $e_vars to the $message.
    	$message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n<br />";
    	
    	if ($debug) { // Show the error.
    	
    		echo '<p class="error">' . $message . '</p>';
    		
    	} else { 
    	
    		// Log the error:
    		error_log ($message, 1, $contact_email); // Send email.
    		
    		// Only print an error message if the error isn't a notice or strict.
    		if ( ($e_number != E_NOTICE) && ($e_number < 2048)) {
    			echo '<p class="error">A system error occurred. We apologize for the inconvenience.</p>';
    		}
    		
    	} // End of $debug IF.
    
    } // End of my_error_handler() definition.
    // Use my error handler:
    set_error_handler ('my_error_handler');
    ?>
    

    copy | embed

    0 comments - tagged in  posted by rlweb on Dec 28, 2008 at 11:39 a.m. EST
Sign up to create your own snipts, or login.