Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorAnže Vodovnik <anvod@microsoft.com>2019-07-02 15:22:38 +0300
committerAnže Vodovnik <anvod@microsoft.com>2019-07-04 11:03:03 +0300
commitea34bbf4acb7ac1436e8509f68151dcf725c7619 (patch)
tree784d422335cac1113d2599b0c624aee27fa82510 /main
parentc847e38e437e427b68f8966cd39a409c4df8e712 (diff)
Added a check for line number and an exception catch clause.
In some cases (like a deletion of code from the document, then trying to double click an existing Search Result), this method might have been called with a line number that no longer exists. This resulted in a call to the API that threw an exception. Now, the method checks the line count in the snapshot, and aborts. Both cases (a graceful failure, and an exception) are logged, so we can see if this continues to happen.
Diffstat (limited to 'main')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Documents/DocumentManager.cs23
1 files changed, 18 insertions, 5 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Documents/DocumentManager.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Documents/DocumentManager.cs
index c01448bdb4..80a607ed29 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Documents/DocumentManager.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Documents/DocumentManager.cs
@@ -657,11 +657,24 @@ namespace MonoDevelop.Ide.Gui.Documents
} else {
var offset = info.Offset;
if (offset < 0) {
- var line = textView.TextSnapshot.GetLineFromLineNumber (info.Line - 1);
- if (info.Column >= 1) {
- offset = line.Start + Math.Min (info.Column - 1, line.Length);
- } else {
- offset = line.Start;
+ try {
+ if (info.Line - 1 > (textView?.TextSnapshot?.LineCount ?? 0)) {
+ LoggingService.LogInfo ($"ScrollToRequestedCaretLocation line was over the snapshot's line count. "
+ + $"Called with {info.Line - 1} but line count was {textView?.TextSnapshot?.LineCount}");
+ return;
+ }
+
+ var line = textView.TextSnapshot.GetLineFromLineNumber (info.Line - 1);
+ if (info.Column >= 1) {
+ offset = line.Start + Math.Min (info.Column - 1, line.Length);
+ } else {
+ offset = line.Start;
+ }
+ } catch (ArgumentException ae) {
+ LoggingService.LogError ($"Calling GetLineFromLineNumber resulted in an argument exception."
+ + $"We tried calling with line number: {info.Line - 1}", ae);
+ // we should just abort in this case, since we can't really do anything
+ return;
}
}
if (editorOperationsFactoryService != null) {