Skip to content

Commit

Permalink
fix(ui): Add logging and hardening around slide out of range error
Browse files Browse the repository at this point in the history
Fixes #49
  • Loading branch information
jcoliz committed Sep 16, 2024
1 parent 677df1d commit d5137b9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion LogoSlideMaker.WinUi/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,22 @@ private void PopulateLayout()
return;
}

var variant = _definition.Variants.Count > 0 ? _definition.Variants[_slideNumber] : new Variant();
var existingVariants = _definition.Variants;
var slideNumber = _slideNumber;

// In case of no variants, we'll use a blank
if (existingVariants.Count == 0)
{
existingVariants = [new()];
}

if (slideNumber >= existingVariants.Count)
{
logWarningSlideOutoFoRange(slideNumber, existingVariants.Count);
slideNumber = 0;
}

var variant = existingVariants[slideNumber];

var engine = new LayoutEngine(_definition, variant);
_layout = engine.CreateSlideLayout();
Expand Down Expand Up @@ -736,5 +751,8 @@ private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
[LoggerMessage(Level = LogLevel.Error, Message = "{Location}: Slide number {Number} out of range {Count}")]
public partial void logFailSlideOutoFoRange(int number, int count, [CallerMemberName] string? location = null);

[LoggerMessage(Level = LogLevel.Warning, Message = "{Location}: Slide number {Number} out of range {Count}")]
public partial void logWarningSlideOutoFoRange(int number, int count, [CallerMemberName] string? location = null);

#endregion
}

0 comments on commit d5137b9

Please sign in to comment.