Changeset 1609


Ignore:
Timestamp:
1/19/2010 5:28:50 AM (4 years ago)
Author:
lowjoel
Message:

A few BlackBox? behavioural changes which should fix #315: Fix handling of corrupt crash reports

  • Crash Reports are named using UTC time
  • We will handle exceptions thrown during the creation of the error report. However, if we do not manage to even write a stack trace, then delete the whole report and abort generation of the report. This is supposed to deal with low-disk space events (which Eraser is good at triggering...)
  • Upon restart, if the Report cannot have its own stack trace loaded, indicative of an error deleting the incomplete report, an InvalidDataException? will be thrown and the report will delete itself (as unanticipated cleanup)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/BlackBox/Eraser.Util/BlackBox.cs

    r1608 r1609  
    268268 
    269269            //Generate a unique identifier for this report. 
    270             string crashName = DateTime.Now.ToString(CrashReportName, CultureInfo.InvariantCulture); 
     270            string crashName = DateTime.Now.ToUniversalTime().ToString( 
     271                CrashReportName, CultureInfo.InvariantCulture); 
    271272            string currentCrashReport = Path.Combine(CrashReportsPath, crashName); 
    272273            Directory.CreateDirectory(currentCrashReport); 
    273274 
    274             //Then write a user-readable summary 
    275             WriteDebugLog(currentCrashReport, e); 
    276  
    277             //Take a screenshot 
    278             WriteScreenshot(currentCrashReport); 
    279  
    280             //Write a memory dump to the folder 
    281             WriteMemoryDump(currentCrashReport, e); 
     275            //Store the steps which we have completed. 
     276            int currentStep = 0; 
     277 
     278            try 
     279            { 
     280                //First, write a user-readable summary 
     281                WriteDebugLog(currentCrashReport, e); 
     282                ++currentStep; 
     283 
     284                //Take a screenshot 
     285                WriteScreenshot(currentCrashReport); 
     286                ++currentStep; 
     287 
     288                //Write a memory dump to the folder 
     289                WriteMemoryDump(currentCrashReport, e); 
     290                ++currentStep; 
     291            } 
     292            catch 
     293            { 
     294                //If an exception was caught while creating the report, we should just 
     295                //abort as that may cause a cascade. However, we need to remove the 
     296                //report folder if the crash report is empty. 
     297                if (currentStep == 0) 
     298                    Directory.Delete(currentCrashReport); 
     299            } 
    282300        } 
    283301 
     
    292310            if (dirInfo.Exists) 
    293311                foreach (DirectoryInfo subDir in dirInfo.GetDirectories()) 
    294                     result.Add(new BlackBoxReport(Path.Combine(CrashReportsPath, subDir.Name))); 
     312                    try 
     313                    { 
     314                        result.Add(new BlackBoxReport(Path.Combine(CrashReportsPath, subDir.Name))); 
     315                    } 
     316                    catch (InvalidDataException) 
     317                    { 
     318                        //Do nothing: invalid reports are automatically deleted. 
     319                    } 
    295320 
    296321            return result.ToArray(); 
     
    374399                //trace do we can check against the server to see if the crash is a new one 
    375400                using (StreamWriter stackTraceLog = new StreamWriter( 
    376                     Path.Combine(dumpFolder, StackTraceFileName))) 
     401                    Path.Combine(dumpFolder, BlackBoxReport.StackTraceFileName))) 
    377402                { 
    378403                    Exception currentException = exception; 
     
    459484        /// </summary> 
    460485        internal static readonly string ScreenshotFileName = "Screenshot.png"; 
    461  
    462         /// <summary> 
    463         /// The file name of the stack trace. 
    464         /// </summary> 
    465         internal static readonly string StackTraceFileName = "Stack Trace.log"; 
    466486    } 
    467487 
     
    480500            Path = path; 
    481501 
     502            string stackTracePath = System.IO.Path.Combine(Path, StackTraceFileName); 
     503            if (!System.IO.File.Exists(stackTracePath)) 
     504            { 
     505                Delete(); 
     506                throw new InvalidDataException("The BlackBox report is corrupt."); 
     507            } 
     508 
    482509            string[] stackTrace = null; 
    483             using (StreamReader reader = new StreamReader( 
    484                 System.IO.Path.Combine(Path, BlackBox.StackTraceFileName))) 
    485             { 
     510            using (StreamReader reader = new StreamReader(stackTracePath)) 
    486511                stackTrace = reader.ReadToEnd().Split(new char[] { '\n' }); 
    487             } 
    488512 
    489513            //Parse the lines in the file. 
     
    543567            { 
    544568                return DateTime.ParseExact(Name, BlackBox.CrashReportName, 
    545                     CultureInfo.InvariantCulture); 
     569                    CultureInfo.InvariantCulture).ToLocalTime(); 
    546570            } 
    547571        } 
     
    640664 
    641665        /// <summary> 
     666        /// The file name of the stack trace. 
     667        /// </summary> 
     668        internal static readonly string StackTraceFileName = "Stack Trace.log"; 
     669 
     670        /// <summary> 
    642671        /// The list of files internal to the report. 
    643672        /// </summary> 
    644673        private static readonly List<string> InternalFiles = new List<string>( 
    645674            new string[] { 
    646                  BlackBox.StackTraceFileName, 
    647                  "Status.txt" 
     675                 StackTraceFileName, 
     676                 StatusFileName 
    648677            } 
    649678        ); 
Note: See TracChangeset for help on using the changeset viewer.