Skip to content

Commit 594c6da

Browse files
authored
Merge pull request #2390 from retailcoder/next
fix in COM wrappers for CodeModule.Clear
2 parents ee64691 + 70a390a commit 594c6da

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

Rubberduck.SourceControl/GitProvider.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,17 @@ public override IEnumerable<IFileStatusEntry> Status()
495495
try
496496
{
497497
base.Status();
498-
return _repo.RetrieveStatus(new StatusOptions {IncludeUnaltered = true, DetectRenamesInWorkDir = true })
499-
.Select(item => new FileStatusEntry(item));
498+
return _repo.RetrieveStatus(new StatusOptions {IncludeUnaltered = true, DetectRenamesInWorkDir = true})
499+
.Select(item => new FileStatusEntry(item));
500500
}
501501
catch (LibGit2SharpException ex)
502502
{
503503
throw new SourceControlException(SourceControlText.GitRepoStatusFailed, ex);
504504
}
505+
catch (SEHException ex)
506+
{
507+
throw new SourceControlException(SourceControlText.GitRepoStatusFailed, ex);
508+
}
505509
}
506510

507511
public override IEnumerable<IFileStatusEntry> LastKnownStatus()

Rubberduck.VBEEditor/SafeComWrappers/VB6/CodeModule.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ public string Content()
8787

8888
public void Clear()
8989
{
90-
Target.DeleteLines(1, CountOfLines);
90+
if (Target.CountOfLines > 0)
91+
{
92+
Target.DeleteLines(1, CountOfLines);
93+
}
9194
}
9295

9396
/// <summary>

Rubberduck.VBEEditor/SafeComWrappers/VBA/CodeModule.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ public string Content()
8787

8888
public void Clear()
8989
{
90-
Target.DeleteLines(1, CountOfLines);
90+
if (Target.CountOfLines > 0)
91+
{
92+
Target.DeleteLines(1, CountOfLines);
93+
}
9194
}
9295

9396
private string _previousContentHash;

Rubberduck.VBEEditor/SafeComWrappers/VBA/VBComponents.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ public void ImportSourceFile(string path)
116116
if (ext == ComponentTypeExtensions.DocClassExtension)
117117
{
118118
var component = this[name];
119+
if (component.IsWrappingNullReference)
120+
{
121+
throw new IndexOutOfRangeException(string.Format("Could not find document component named '{0}'.", name));
122+
}
119123
component.CodeModule.Clear();
120124
component.CodeModule.AddFromString(codeString);
121125
}
122126
else if (ext == ComponentTypeExtensions.FormExtension)
123127
{
124-
IVBComponent component;
125-
try
126-
{
127-
component = this[name];
128-
}
129-
catch
128+
var component = this[name];
129+
if (component.IsWrappingNullReference)
130130
{
131131
component = Add(ComponentType.UserForm);
132132
component.Properties["Caption"].Value = name;

0 commit comments

Comments
 (0)