Skip to content

Commit

Permalink
Merge pull request #78 from yatli/crash_report
Browse files Browse the repository at this point in the history
Crash report
  • Loading branch information
Yatao Li authored Sep 26, 2019
2 parents 2fda012 + 6806678 commit 3b70ad5
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 11 deletions.
Binary file added Assets/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/error.xcf
Binary file not shown.
11 changes: 11 additions & 0 deletions DesignTime/CrashReportSampleData.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace FVim

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"
]

32 changes: 21 additions & 11 deletions Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,25 @@ let main(args: string[]) =
let _ = builder.SetupWithoutStarting()
// Avalonia is initialized. SynchronizationContext-reliant code should be working by now;

try
Model.Start opts
with ex -> ()
let cfg = config.load()
let cwd = Environment.CurrentDirectory |> Path.GetFullPath
let workspace = cfg.Workspace |> Array.tryFind(fun w -> w.Path = cwd)
let mainwin = new MainWindowViewModel(workspace)
lifetime.MainWindow <- MainWindow(DataContext = mainwin)
let ret = lifetime.Start(args)
let model_start =
try
Model.Start opts
Ok()
with ex -> Error ex

config.save cfg (int mainwin.X) (int mainwin.Y) mainwin.Width mainwin.Height mainwin.WindowState
ret
match model_start with
| Ok() ->
let cfg = config.load()
let cwd = Environment.CurrentDirectory |> Path.GetFullPath
let workspace = cfg.Workspace |> Array.tryFind(fun w -> w.Path = cwd)
let mainwin = new MainWindowViewModel(workspace)
lifetime.MainWindow <- MainWindow(DataContext = mainwin)
let ret = lifetime.Start(args)

config.save cfg (int mainwin.X) (int mainwin.Y) mainwin.Width mainwin.Height mainwin.WindowState
ret
| Error ex ->
let crash = new CrashReportViewModel(ex)
lifetime.MainWindow <- new CrashReport(DataContext = crash)
ignore <| lifetime.Start(args)
-1
23 changes: 23 additions & 0 deletions ViewModels/CrashReportViewModel.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace FVim

open ui
open log
open common

type CrashReportViewModel(ex: exn) =
inherit ViewModelBase()
member __.MainMessage =
ex.Message
member __.StackTrace =
ex.StackTrace.Split("\n")
member __.TipMessage =
let tip =
match ex.Message with
| "The system cannot find the file specified." -> "Tip: check your neovim installation. `nvim` is not in your $PATH.\n"
| _ -> ""
let generic_message =
"You can go to /~https://github.com/yatli/fvim/issues, and search\n" +
"for relevant issues with the exception message, or the stack trace.\n" +
"Feel free to create new issues, and I'll help to triage and fix the problem."
tip + generic_message

34 changes: 34 additions & 0 deletions Views/CrashReport.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Window xmlns="/~https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:fvim="clr-namespace:FVim;assembly=FVim"
Focusable="True"
MinHeight="240"
MinWidth="600"
Icon="..\Assets\fvim.png"
x:Class="FVim.CrashReport">
<Design.DataContext>
<fvim:CrashReportSampleData />
</Design.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="40" />
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" />
<ColumnDefinition Width="400" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<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" />
<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"/>
</Grid>
</Window>
13 changes: 13 additions & 0 deletions Views/CrashReport.xaml.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace FVim

open ui
open log
open common
open Avalonia.Markup.Xaml
open Avalonia.Controls

type CrashReport() as this =
inherit Window()

do
AvaloniaXamlLoader.Load(this)
3 changes: 3 additions & 0 deletions fvim.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="DesignTime\CrashReportSampleData.fs" />
<Compile Include="common.fs" />
<Compile Include="config.fs" />
<Compile Include="getopt.fs" />
Expand All @@ -41,12 +42,14 @@
<Compile Include="ViewModels\PopupMenuViewModel.fs" />
<Compile Include="ViewModels\EditorViewModel.fs" />
<Compile Include="ViewModels\MainWindowViewModel.fs" />
<Compile Include="ViewModels\CrashReportViewModel.fs" />
<Compile Include="Views\ViewBase.fs" />
<Compile Include="Views\MainWindow.xaml.fs" />
<Compile Include="Views\CompletionItem.xaml.fs" />
<Compile Include="Views\PopupMenu.xaml.fs" />
<Compile Include="Views\Editor.xaml.fs" />
<Compile Include="Views\Cursor.xaml.fs" />
<Compile Include="Views\CrashReport.xaml.fs" />
<Compile Include="App.xaml.fs" />
<Compile Include="Program.fs" />
<ApplicationDefinition Include="fvim.config" />
Expand Down

0 comments on commit 3b70ad5

Please sign in to comment.