Skip to content

Commit

Permalink
add error boundaries to simulation view code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcl committed Sep 7, 2024
1 parent 8ed7971 commit 82fda62
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 40 deletions.
50 changes: 29 additions & 21 deletions src/Renderer/UI/WaveSim/WaveSimRams.fs
Original file line number Diff line number Diff line change
Expand Up @@ -239,28 +239,36 @@ let ramTable (dispatch: Msg -> unit) (wsModel: WaveSimModel) (model: Model) ((ra

/// Bulma Level component of tables showing RAM contents.
let ramTables (dispatch: Msg -> unit) (wsModel: WaveSimModel) (model: Model): ReactElement =
let inlineStyle (styles:CSSProp list) = div [Style (Display DisplayOptions.Inline :: styles)]
let start = TimeHelpers.getTimeMs ()
let selectedRams = Map.toList wsModel.SelectedRams
if List.length selectedRams > 0 then
let tables =
let headerRow =
["read", RAMRead; "overwritten",RAMWritten]
|> List.map (fun (op, opStyle) -> inlineStyle [Margin "0px"] [inlineStyle (ramTableRowStyle opStyle) [str op]])
|> function
| [a;b] -> [str "Key: Memory location is " ; a; str ", or " ;b; str ". Click waveforms or use cursor control to change current cycle."]
| x ->
printfn $"Unexpected failure in ramTables: x = {x}"
failwithf "What? Can't happen!"
List.map (fun ram -> td [Style [BorderColor "white"]] [ramTable dispatch wsModel model ram]) selectedRams
|> (fun tables -> [tbody [] [tr [] [th [ColSpan selectedRams.Length] [inlineStyle [] headerRow]]; tr [Style [Border "10px"]] tables]])
|> Fulma.Table.table [
Table.TableOption.Props ramTablesLevelProps;
Table.IsFullWidth;
Table.IsBordered;
]
div [HTMLAttr.Id "TablesDiv"] [ hr [ Style [ Margin "5px"]]; br [ Style [ Margin "0px"]]; tables]
else div [] []
try
let inlineStyle (styles:CSSProp list) = div [Style (Display DisplayOptions.Inline :: styles)]

let selectedRams = Map.toList wsModel.SelectedRams
if List.length selectedRams > 0 then
let tables =
let headerRow =
["read", RAMRead; "overwritten",RAMWritten]
|> List.map (fun (op, opStyle) -> inlineStyle [Margin "0px"] [inlineStyle (ramTableRowStyle opStyle) [str op]])
|> function
| [a;b] -> [str "Key: Memory location is " ; a; str ", or " ;b; str ". Click waveforms or use cursor control to change current cycle."]
| x ->
printfn $"Unexpected failure in ramTables: x = {x}"
failwithf "What? Can't happen!"
List.map (fun ram -> td [Style [BorderColor "white"]] [ramTable dispatch wsModel model ram]) selectedRams
|> (fun tables -> [tbody [] [tr [] [th [ColSpan selectedRams.Length] [inlineStyle [] headerRow]]; tr [Style [Border "10px"]] tables]])
|> Fulma.Table.table [
Table.TableOption.Props ramTablesLevelProps;
Table.IsFullWidth;
Table.IsBordered;
]
div [HTMLAttr.Id "TablesDiv"] [ hr [ Style [ Margin "5px"]]; br [ Style [ Margin "0px"]]; tables]
else div [] []
with
// An error here is probably because the view code is displaying RAMs before simulation had finished.
// It is not fatal, and does no harm to the simulation. This error boundary ignores the error printing
// a message to the console, and displaying a blank div.
| e -> printfn "Error in ramTables display: %A" e.Message
div [] []
|> TimeHelpers.instrumentInterval "ramTables" start


46 changes: 27 additions & 19 deletions src/Renderer/UI/WaveSim/WaveSimWaveforms.fs
Original file line number Diff line number Diff line change
Expand Up @@ -283,23 +283,31 @@ let waveformColumn (wsModel: WaveSimModel) dispatch : ReactElement =

/// Display the names, waveforms, and values of selected waveforms
let showWaveforms (model: Model) (wsModel: WaveSimModel) (dispatch: Msg -> unit) : ReactElement =
if List.isEmpty wsModel.SelectedWaves then
div [] [] // no waveforms
else
let wHeight = calcWaveformHeight wsModel
let fixedHeight = Constants.softScrollBarWidth + Constants.topHalfHeight
let cssHeight =
if wsModel.SelectedRams.Count > 0 then
$"min( calc(50vh - (0.5 * {fixedHeight}px)) , {wHeight}px)"
else
$"min( calc(100vh - {fixedHeight}px) , {wHeight}px)"

div [ HTMLAttr.Id "Scroller"; Style [ Height cssHeight; Width "100%"; CSSProp.Custom("overflow", "hidden auto")]] [
div [ HTMLAttr.Id "WaveCols" ;showWaveformsStyle ]
[
namesColumn model wsModel dispatch
waveformColumn wsModel dispatch
valuesColumn wsModel
try
if List.isEmpty wsModel.SelectedWaves then
div [] [] // no waveforms
else
let wHeight = calcWaveformHeight wsModel
let fixedHeight = Constants.softScrollBarWidth + Constants.topHalfHeight
let cssHeight =
if wsModel.SelectedRams.Count > 0 then
$"min( calc(50vh - (0.5 * {fixedHeight}px)) , {wHeight}px)"
else
$"min( calc(100vh - {fixedHeight}px) , {wHeight}px)"

div [ HTMLAttr.Id "Scroller"; Style [ Height cssHeight; Width "100%"; CSSProp.Custom("overflow", "hidden auto")]] [
div [ HTMLAttr.Id "WaveCols" ;showWaveformsStyle ]
[
namesColumn model wsModel dispatch
waveformColumn wsModel dispatch
valuesColumn wsModel
]
]
]

with
// Catch any exceptions during waveform view calculation and display an error message.
// an error here is probably because the simulation has finished
// and is not fatal. this error boundary ignores the error
// and displays a blank div.
| ex ->
printfn $"Error in showWaveforms: {ex.Message}"
div [] []

0 comments on commit 82fda62

Please sign in to comment.