Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better exception handling in transition list input - in particular make the FileModifiedException more informative #3202

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
22 changes: 22 additions & 0 deletions pwiz_tools/Skyline/Model/SrmDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,17 @@ public SrmDocument ImportMassList(MassListInputs inputs,
Replace(TextUtil.SEPARATOR_TSV_STR, @" ");
errorList.Add(new TransitionImportErrorInfo(x.PlainMessage, x.ColumnIndex, x.LineNumber + 1, line)); // CONSIDER: worth the effort to pull row and column info from error message?
}
catch (Exception ex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right place to put this. This is supposed to be for issues with parsing a line, not for global errors. You should be catching other exceptions higher up the callstack.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching it here is advantageous as it ties into the reporting mechanism for both the UI and commandline use cases.

{
if (ExceptionUtil.IsProgrammingDefect(ex))
{
throw; // Let it fall through so we hear about it on ExceptionWeb
}
else
{
errorList.Add(new TransitionImportErrorInfo(ex.Message, null, null, string.Empty));
}
}
}
else
{
Expand Down Expand Up @@ -1544,6 +1555,17 @@ public SrmDocument ImportMassList(MassListInputs inputs,
{
errorList.Add(new TransitionImportErrorInfo(x));
}
catch (Exception ex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right place to put this. This is supposed to be for issues with parsing a line, not for global errors. You should be catching other exceptions higher up the callstack.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching it here is advantageous as it ties into the reporting mechanism for both the UI and commandline use cases.

{
if (ExceptionUtil.IsProgrammingDefect(ex))
{
throw; // Let it fall through so we hear about it on ExceptionWeb
}
else
{
errorList.Add(new TransitionImportErrorInfo(ex.Message, null, null, string.Empty));
}
}
}
return docNew;
}
Expand Down
9 changes: 7 additions & 2 deletions pwiz_tools/Skyline/Util/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2121,14 +2121,19 @@ public static string GetExceptionText(Exception exception, StackTrace stackTrace
/// </summary>
public static bool IsProgrammingDefect(Exception exception)
{
if (exception is FileModifiedException)
{
return true; // Unexpected change to file, we'd like to hear about that
}

if (exception is InvalidDataException
|| exception is IOException
|| exception is UnauthorizedAccessException)
{
return false;
return false; // Presumably something like bad data format, or write access violation etc, that user can deal with
}

return true;
return true; // Something that we'd like to hear about
}

/// <summary>
Expand Down
20 changes: 16 additions & 4 deletions pwiz_tools/Skyline/Util/UtilIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ protected override IDisposable Connect()
// Check to see if the file was modified, during the time
// it was closed.
if (IsModified)
throw new FileModifiedException(string.Format(UtilResources.PooledFileStream_Connect_The_file__0__has_been_modified_since_it_was_first_opened, FilePath));
throw new FileModifiedException(string.Format(UtilResources.PooledFileStream_Connect_The_file__0__has_been_modified_since_it_was_first_opened, FilePath) +
string.Format($@" ({ModifiedExplanation})"));
// Create the stream
return StreamManager.CreateStream(FilePath, FileMode.Open, Buffered);
}
Expand Down Expand Up @@ -471,9 +472,20 @@ public string ModifiedExplanation
{
get
{
if (!IsModified)
return @"Unmodified";
return FileEx.GetElapsedTimeExplanation(FileTime, File.GetLastWriteTime(FilePath));
try
{
if (!IsModified)
return @"Unmodified";
return @"file time - file last write time: " + FileEx.GetElapsedTimeExplanation(FileTime, File.GetLastWriteTime(FilePath));
}
catch (UnauthorizedAccessException e)
{
return $@"UnauthorizedAccessException: {e.Message}";
}
catch (IOException e)
{
return $@"IOException: {e.Message}";
}
}
}

Expand Down