Skip to content

Commit 6991bc8

Browse files
committed
Make all places using suspension inspect the result
Also contains some naming adjustments based on review comments to PR #5274.
1 parent 9be7204 commit 6991bc8

File tree

7 files changed

+46
-12
lines changed

7 files changed

+46
-12
lines changed

Rubberduck.Core/UI/CodeExplorer/CodeExplorerAddComponentService.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Runtime.ExceptionServices;
34
using System.Text;
45
using Rubberduck.Navigation.CodeExplorer;
56
using Rubberduck.Parsing.VBA;
@@ -32,10 +33,17 @@ public void AddComponent(CodeExplorerItemViewModel node, ComponentType component
3233

3334
var prefixInModule = FolderAnnotation(node);
3435

35-
_parseManager.OnSuspendParser(
36+
var suspensionResult = _parseManager.OnSuspendParser(
3637
this,
3738
Enum.GetValues(typeof(ParserState)).Cast<ParserState>(),
3839
() => _addComponentService.AddComponent(projectId, componentType, code, prefixInModule));
40+
41+
if (suspensionResult.Outcome == SuspensionOutcome.UnexpectedError
42+
&& suspensionResult.EncounteredException != null)
43+
{
44+
//This rethrows with the original stack trace.
45+
ExceptionDispatchInfo.Capture(suspensionResult.EncounteredException).Throw();
46+
}
3947
}
4048

4149
public void AddComponentWithAttributes(CodeExplorerItemViewModel node, ComponentType componentType, string code, string additionalPrefixInModule = null)
@@ -60,10 +68,17 @@ public void AddComponentWithAttributes(CodeExplorerItemViewModel node, Component
6068
}
6169
var prefixInModule = modulePrefix.ToString();
6270

63-
_parseManager.OnSuspendParser(
71+
var suspensionResult = _parseManager.OnSuspendParser(
6472
this,
6573
Enum.GetValues(typeof(ParserState)).Cast<ParserState>(),
6674
() => _addComponentService.AddComponentWithAttributes(projectId, componentType, code, prefixInModule));
75+
76+
if (suspensionResult.Outcome == SuspensionOutcome.UnexpectedError
77+
&& suspensionResult.EncounteredException != null)
78+
{
79+
//This rethrows with the original stack trace.
80+
ExceptionDispatchInfo.Capture(suspensionResult.EncounteredException).Throw();
81+
}
6782
}
6883

6984
private string ProjectId(CodeExplorerItemViewModel node)

Rubberduck.Core/UI/CodeExplorer/Commands/ImportCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ protected void ImportFiles(ICollection<string> filesToImport, IVBProject targetP
216216

217217
var existingModules = Modules(moduleNames, targetProject.ProjectId, finder);
218218

219-
if (!ExistingModulesAreGenerallyOk(existingModules))
219+
if (!ExistingModulesPassPreCheck(existingModules))
220220
{
221221
return;
222222
}
@@ -274,7 +274,7 @@ protected void ImportFiles(ICollection<string> filesToImport, IVBProject targetP
274274
.Where(module => reImportableComponentTypes.Contains(module.ComponentType))
275275
.ToList();
276276

277-
if (UserDeniesExecution(targetProject))
277+
if (UserDeclinesExecution(targetProject))
278278
{
279279
return;
280280
}
@@ -303,9 +303,9 @@ protected void ImportFiles(ICollection<string> filesToImport, IVBProject targetP
303303
}
304304
}
305305

306-
protected virtual bool ExistingModulesAreGenerallyOk(IDictionary<string, QualifiedModuleName> existingModules) => true;
306+
protected virtual bool ExistingModulesPassPreCheck(IDictionary<string, QualifiedModuleName> existingModules) => true;
307307
protected virtual ICollection<QualifiedModuleName> ModulesToRemoveBeforeImport(IDictionary<string, QualifiedModuleName> existingModules) => new List<QualifiedModuleName>();
308-
protected virtual bool UserDeniesExecution(IVBProject targetProject) => false;
308+
protected virtual bool UserDeclinesExecution(IVBProject targetProject) => false;
309309

310310
protected bool HasMatchingFileExtension(string filename, QualifiedModuleName module)
311311
{

Rubberduck.Core/UI/CodeExplorer/Commands/ReplaceProjectContentsFromFilesCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected override ICollection<QualifiedModuleName> ModulesToRemoveBeforeImport(
3939
.ToHashSet();
4040
}
4141

42-
protected override bool UserDeniesExecution(IVBProject targetProject)
42+
protected override bool UserDeclinesExecution(IVBProject targetProject)
4343
{
4444
return !UserConfirmsToReplaceProjectContents(targetProject);
4545
}

Rubberduck.Core/UI/CodeExplorer/Commands/UpdateFromFileCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public UpdateFromFilesCommand(
3838
//Since we remove the components, we keep on the safe side.
3939
protected override IEnumerable<string> AlwaysImportableExtensions => Enumerable.Empty<string>();
4040

41-
protected override bool ExistingModulesAreGenerallyOk(IDictionary<string, QualifiedModuleName> existingModules)
41+
protected override bool ExistingModulesPassPreCheck(IDictionary<string, QualifiedModuleName> existingModules)
4242
{
4343
if (!existingModules.All(kvp => HasMatchingFileExtension(kvp.Key, kvp.Value)))
4444
{

Rubberduck.Parsing/Rewriter/AttributesRewriteSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected override bool TryRewriteInternal()
3434
var result = _parseManager.OnSuspendParser(this, new[] {ParserState.Ready, ParserState.ResolvedDeclarations}, ExecuteAllRewriters);
3535
if(result.Outcome != SuspensionOutcome.Completed)
3636
{
37-
Logger.Warn($"Rewriting attribute modules did not succeed. suspension result = {result}");
37+
Logger.Warn($"Rewriting attribute modules did not succeed. Suspension result = {result}");
3838
if (result.EncounteredException != null)
3939
{
4040
Logger.Warn(result.EncounteredException);

Rubberduck.Parsing/VBA/IParseManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public interface IParseManager : IParserStatusProvider
3232
void MarkAsModified(QualifiedModuleName module);
3333
}
3434

35-
36-
3735
public enum SuspensionOutcome
3836
{
3937
/// <summary>

Rubberduck.UnitTesting/UnitTesting/TestEngine.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,28 @@ protected virtual void RunInternal(IEnumerable<TestMethod> tests)
179179
return;
180180
}
181181
//We push the suspension to a background thread to avoid potential deadlocks if a parse is still running.
182-
Task.Run(() => _state.OnSuspendParser(this, AllowedRunStates, () => RunWhileSuspended(tests)));
182+
Task.Run(() =>
183+
{
184+
var suspensionResult = _state.OnSuspendParser(this, AllowedRunStates, () => RunWhileSuspended(tests));
185+
186+
//We have to log and swallow since we run as the top level code in a background thread.
187+
switch (suspensionResult.Outcome)
188+
{
189+
case SuspensionOutcome.Completed:
190+
return;
191+
case SuspensionOutcome.Canceled:
192+
Logger.Debug("Test execution canceled.");
193+
return;
194+
default:
195+
Logger.Warn($"Test execution failed with suspension outcome {suspensionResult.Outcome}.");
196+
if (suspensionResult.EncounteredException != null)
197+
{
198+
Logger.Error(suspensionResult.EncounteredException);
199+
}
200+
201+
return;
202+
}
203+
});
183204
}
184205

185206
private void EnsureRubberduckIsReferencedForEarlyBoundTests()

0 commit comments

Comments
 (0)