Skip to content

Commit

Permalink
enhanced error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Nov 12, 2020
1 parent df8c9e3 commit 3fd455a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 37 deletions.
7 changes: 1 addition & 6 deletions DesignTime/CrashReportSampleData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,4 @@
type CrashReportSampleData() =
member __.MainMessage = "Some error: some detailed error message.\nThis error is so bad that we have to bail out."
member __.TipMessage = "\n\nIn case of fire,\n 1. git commit\n 2. git push\n 3. run\nThank you for your cooperation."
member __.StackTrace = System.Collections.Generic.List [
"foo"
"bar"
"baz"
]

member __.StackTrace = "foo\nbar\nbaz"
44 changes: 24 additions & 20 deletions Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ type MsgPackResolver() =
else
s_resolver.GetFormatter<'a>()

let initializeAvaloniaLifetime() =
// Avalonia initialization
let builder = buildAvaloniaApp()
let lifetime = new ClassicDesktopStyleApplicationLifetime()
lifetime.ShutdownMode <- Controls.ShutdownMode.OnMainWindowClose
let _ = builder.SetupWithLifetime(lifetime)
// Avalonia is initialized. SynchronizationContext-reliant code should be working by now;
lifetime


[<EntryPoint>]
[<STAThread>]
Expand All @@ -77,23 +86,18 @@ let main(args: string[]) =
)
System.Console.OutputEncoding <- System.Text.Encoding.Unicode

let opts = parseOptions args
FVim.log.init opts
match opts.intent with
| Setup -> setup()
| Uninstall -> uninstall()
| Daemon(port, pipe) -> daemon port pipe opts
| Start ->

// Avalonia initialization
let builder = buildAvaloniaApp()
let lifetime = new ClassicDesktopStyleApplicationLifetime()
lifetime.ShutdownMode <- Controls.ShutdownMode.OnMainWindowClose
let _ = builder.SetupWithLifetime(lifetime)
// Avalonia is initialized. SynchronizationContext-reliant code should be working by now;
let lifetime = lazy initializeAvaloniaLifetime()

try
Model.Start opts
let opts = parseOptions args
FVim.log.init opts
match opts.intent with
| Setup -> setup()
| Uninstall -> uninstall()
| Daemon(port, pipe) -> daemon port pipe opts
| Start ->
lifetime.Force() |> ignore
Model.Start opts
Ok()
with ex -> Error ex
|> function
Expand All @@ -108,9 +112,9 @@ let main(args: string[]) =
|> ignore

let mainwin = new MainWindowViewModel(workspace)
lifetime.MainWindow <- MainWindow(DataContext = mainwin)
lifetime.Value.MainWindow <- MainWindow(DataContext = mainwin)
try
ignore <| lifetime.Start(args)
ignore <| lifetime.Value.Start(args)
let x, y, w, h =
let x, y, w, h = (int mainwin.X), (int mainwin.Y), (int mainwin.Width), (int mainwin.Height)
// sometimes the metrics will just go off...
Expand All @@ -126,11 +130,11 @@ let main(args: string[]) =
|> function
| Ok() -> 0
| Error ex ->
// TODO should yield so that the crash info can propagate back
lifetime.Force() |> ignore
FVim.log.trace "main" "%s" "displaying crash dialog"
let code, msgs = States.get_crash_info()
let crash = new CrashReportViewModel(ex, code, msgs)
let win = new CrashReport(DataContext = crash)
lifetime.MainWindow <- win
ignore <| lifetime.Start(args)
lifetime.Value.MainWindow <- win
ignore <| lifetime.Value.Start(args)
-1
4 changes: 2 additions & 2 deletions ViewModels/CrashReportViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ type CrashReportViewModel(ex: exn, code: int, msgs: ResizeArray<string>) =
inherit ViewModelBase()
member __.MainMessage =
sprintf "Exit code: %d\n" code +
ex.Message + "\n" +
sprintf "Exception message: %s\n" ex.Message +
join msgs
member __.StackTrace =
ex.StackTrace.Split("\n")
ex.StackTrace
member __.TipMessage =
let tip =
match ex.Message.Trim() with
Expand Down
8 changes: 5 additions & 3 deletions Views/CrashReport.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="40" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
Expand All @@ -26,9 +26,11 @@
<TextBlock Text="FVim exited unexpectedly." Grid.Row="0" Grid.Column="1" Margin="0,10,0,0" FontWeight="Bold"/>
<TextBlock Text="Close this window to exit FVim." Grid.Row="3" Grid.Column="1" Margin="0,10,0,0" FontWeight="Bold"/>
<Image Source="/Assets/error.png" Grid.Row="0" Grid.RowSpan="4" Grid.Column="0" Height="64" Margin="0,0,0,50" />
<TextBlock Text="{Binding MainMessage}" Grid.Row="1" Grid.Column="1" Margin="0,20,0,0" />
<TextBox Text="{Binding MainMessage}" Grid.Row="1" Grid.Column="1" Margin="0,20,0,0"
AcceptsReturn="True" TextWrapping="Wrap" />
<TextBlock Text="{Binding TipMessage}" Grid.Row="2" Grid.Column="1" Margin="0,20,0,0" />
<TextBlock Text="Stack trace:" Grid.Row="0" Grid.Column="2" Margin="0,10,0,0"/>
<ListBox Items="{Binding StackTrace}" Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" Margin="10,10,10,10"/>
<TextBox Text="{Binding StackTrace}" Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" Margin="10,10,10,10"
AcceptsReturn="True" TextWrapping="Wrap" />
</Grid>
</Window>
7 changes: 1 addition & 6 deletions shell.fs
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,13 @@ let setup() =
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
if win32CheckUAC() then
win32RegisterFileAssociation()

// setup finished.
0

let uninstall() =
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
if win32CheckUAC() then
win32UnregisterFileAssociation()

// setup finished.
0
// uninstall finished.

let daemon (port: uint16 option) (pipe: string option) {args=args; program=program; stderrenc = enc} =
trace "%s" "Running as daemon."
Expand Down Expand Up @@ -177,4 +173,3 @@ let daemon (port: uint16 option) (pipe: string option) {args=args; program=progr
trace "Neovim process started. Pid = %d" proc.Id
proc.WaitForExit()
trace "Neovim process terminated. ExitCode = %d" proc.ExitCode
0

0 comments on commit 3fd455a

Please sign in to comment.