Skip to content

Commit 3b7a8df

Browse files
committed
Log exceptions
1 parent ab4e32c commit 3b7a8df

File tree

7 files changed

+60
-38
lines changed

7 files changed

+60
-38
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using Ninject.Extensions.Interception;
3+
using NLog;
4+
5+
namespace Rubberduck.Root
6+
{
7+
/// <summary>
8+
/// An interceptor that logs an unhandled exception.
9+
/// </summary>
10+
public class FatalExceptionInterceptor : InterceptorBase
11+
{
12+
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
13+
14+
protected override void OnError(IInvocation invocation, Exception exception)
15+
{
16+
_logger.Fatal(exception);
17+
throw new InterceptedException(exception);
18+
}
19+
}
20+
}

RetailCoder.VBE/Root/RubberduckModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private void ApplyDefaultInterfacesConvention(IEnumerable<Assembly> assemblies)
170170
// inspections & factories have their own binding rules
171171
.Where(type => !type.Name.EndsWith("Factory") && !type.Name.EndsWith("ConfigProvider") && !type.GetInterfaces().Contains(typeof(IInspection)))
172172
.BindDefaultInterface()
173-
.Configure(binding => binding.InThreadScope())); // TransientScope wouldn't dispose disposables
173+
.Configure(binding => binding.InThreadScope().Intercept().With<FatalExceptionInterceptor>())); // TransientScope wouldn't dispose disposables
174174
}
175175

176176
// note: settings namespace classes are injected in singleton scope

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@
391391
<Compile Include="Refactorings\ExtractMethod\IExtractMethodProc.cs" />
392392
<Compile Include="Refactorings\ExtractMethod\IExtractMethodRule.cs" />
393393
<Compile Include="Refactorings\ExtractMethod\IExtractMethodSelectionValidation.cs" />
394+
<Compile Include="Root\FatalExceptionInterceptor.cs" />
394395
<Compile Include="Root\EnumerableCounterInterceptor.cs" />
395396
<Compile Include="Root\InterceptedException.cs" />
396397
<Compile Include="Root\InterceptorBase.cs" />

RetailCoder.VBE/UI/SourceControl/BranchesViewViewModel.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ public string CurrentBranch
124124
{
125125
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
126126
}
127-
catch (Exception e)
127+
catch
128128
{
129-
Logger.Fatal(e);
130129
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
131130
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
131+
throw;
132132
}
133133
OnLoadingComponentsCompleted();
134134
}
@@ -307,11 +307,11 @@ private void CreateBranchOk()
307307
{
308308
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
309309
}
310-
catch (Exception e)
310+
catch
311311
{
312-
Logger.Fatal(e);
313312
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
314313
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
314+
throw;
315315
}
316316

317317
DisplayCreateBranchGrid = false;
@@ -342,11 +342,11 @@ private void MergeBranchOk()
342342
OnLoadingComponentsCompleted();
343343
return;
344344
}
345-
catch (Exception e)
345+
catch
346346
{
347-
Logger.Fatal(e);
348347
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
349348
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
349+
throw;
350350
}
351351

352352
DisplayMergeBranchesGrid = false;
@@ -371,11 +371,11 @@ private void DeleteBranch(bool isBranchPublished)
371371
{
372372
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
373373
}
374-
catch (Exception e)
374+
catch
375375
{
376-
Logger.Fatal(e);
377376
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
378377
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
378+
throw;
379379
}
380380

381381
RefreshView();
@@ -400,11 +400,11 @@ private void PublishBranch()
400400
{
401401
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
402402
}
403-
catch (Exception e)
403+
catch
404404
{
405-
Logger.Fatal(e);
406405
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
407406
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
407+
throw;
408408
}
409409

410410
RefreshView();
@@ -421,11 +421,11 @@ private void UnpublishBranch()
421421
{
422422
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
423423
}
424-
catch (Exception e)
424+
catch
425425
{
426-
Logger.Fatal(e);
427426
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
428427
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
428+
throw;
429429
}
430430

431431
RefreshView();

RetailCoder.VBE/UI/SourceControl/ChangesViewViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ private void UndoChanges(IFileStatusEntry fileStatusEntry)
148148
{
149149
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
150150
}
151-
catch (Exception e)
151+
catch
152152
{
153-
Logger.Fatal(e);
154153
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
155154
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
155+
throw;
156156
}
157157
}
158158

@@ -203,11 +203,11 @@ private void Commit()
203203
{
204204
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
205205
}
206-
catch (Exception e)
206+
catch
207207
{
208-
Logger.Fatal(e);
209208
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
210209
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
210+
throw;
211211
}
212212

213213
CommitMessage = string.Empty;

RetailCoder.VBE/UI/SourceControl/SourceControlViewViewModel.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,12 @@ private void InitRepo()
604604
ViewModel_ErrorThrown(this,
605605
new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
606606
}
607-
catch (Exception e)
607+
catch
608608
{
609-
Logger.Fatal(e);
610609
ViewModel_ErrorThrown(this,
611610
new ErrorEventArgs(RubberduckUI.SourceControl_UnknownErrorTitle,
612611
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error));
612+
throw;
613613
}
614614

615615
Status = RubberduckUI.Online;
@@ -684,12 +684,12 @@ private void OpenRepo()
684684
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
685685
return;
686686
}
687-
catch (Exception e)
687+
catch
688688
{
689-
Logger.Fatal(e);
690689
ViewModel_ErrorThrown(this,
691690
new ErrorEventArgs(RubberduckUI.SourceControl_UnknownErrorTitle,
692691
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error));
692+
throw;
693693
}
694694

695695
OnOpenRepoCompleted();
@@ -731,12 +731,12 @@ private void CloneRepo(SecureCredentials credentials = null)
731731
ViewModel_ErrorThrown(this, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
732732
return;
733733
}
734-
catch (Exception e)
734+
catch
735735
{
736-
Logger.Fatal(e);
737736
ViewModel_ErrorThrown(this,
738737
new ErrorEventArgs(RubberduckUI.SourceControl_UnknownErrorTitle,
739738
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error));
739+
throw;
740740
}
741741

742742
_isCloning = false;
@@ -766,12 +766,12 @@ private void PublishRepo()
766766
{
767767
ViewModel_ErrorThrown(null, new ErrorEventArgs(ex.Message, ex.InnerException.Message, NotificationType.Error));
768768
}
769-
catch (Exception e)
769+
catch
770770
{
771-
Logger.Fatal(e);
772771
ViewModel_ErrorThrown(this,
773772
new ErrorEventArgs(RubberduckUI.SourceControl_UnknownErrorTitle,
774773
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error));
774+
throw;
775775
}
776776

777777
OnPropertyChanged("RepoDoesNotHaveRemoteLocation");
@@ -809,11 +809,12 @@ private void OpenCommandPrompt()
809809
{
810810
Process.Start(_config.CommandPromptLocation);
811811
}
812-
catch (Exception e)
812+
catch
813813
{
814814
ViewModel_ErrorThrown(this,
815-
new ErrorEventArgs(RubberduckUI.SourceControl_OpenCommandPromptFailureTitle, e.Message,
816-
NotificationType.Error));
815+
new ErrorEventArgs(RubberduckUI.SourceControl_UnknownErrorTitle,
816+
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error));
817+
throw;
817818
}
818819
}
819820

@@ -840,12 +841,12 @@ private void OpenRepoAssignedToProject()
840841
_config.Repositories.Remove(_config.Repositories.FirstOrDefault(repo => repo.Id == _vbe.ActiveVBProject.HelpFile));
841842
_configService.Save(_config);
842843
}
843-
catch (Exception e)
844+
catch
844845
{
845-
Logger.Fatal(e);
846846
ViewModel_ErrorThrown(this,
847847
new ErrorEventArgs(RubberduckUI.SourceControl_UnknownErrorTitle,
848848
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error));
849+
throw;
849850
}
850851

851852
OnOpenRepoCompleted();

RetailCoder.VBE/UI/SourceControl/UnsyncedCommitsViewViewModel.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ private void FetchCommits()
106106
{
107107
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
108108
}
109-
catch (Exception e)
109+
catch
110110
{
111-
Logger.Fatal(e);
112111
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
113112
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
113+
throw;
114114
}
115115
}
116116

@@ -127,11 +127,11 @@ private void PullCommits()
127127
{
128128
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
129129
}
130-
catch (Exception e)
130+
catch
131131
{
132-
Logger.Fatal(e);
133132
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
134133
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
134+
throw;
135135
}
136136
}
137137

@@ -148,11 +148,11 @@ private void PushCommits()
148148
{
149149
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
150150
}
151-
catch (Exception e)
151+
catch
152152
{
153-
Logger.Fatal(e);
154153
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
155154
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
155+
throw;
156156
}
157157
}
158158

@@ -170,11 +170,11 @@ private void SyncCommits()
170170
{
171171
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
172172
}
173-
catch (Exception e)
173+
catch
174174
{
175-
Logger.Fatal(e);
176175
RaiseErrorEvent(RubberduckUI.SourceControl_UnknownErrorTitle,
177176
RubberduckUI.SourceControl_UnknownErrorMessage, NotificationType.Error);
177+
throw;
178178
}
179179
}
180180

0 commit comments

Comments
 (0)