Skip to content

Conversation

@AndisGrossteins
Copy link
Contributor

Fixes #468

The check for invalid font name and falling back to default font might be better placed in LogExpert.Config.ConfigManager but I've added it in LogWindow where the exception was thrown blocking application startup.

@Hirogen
Copy link
Collaborator

Hirogen commented Sep 24, 2025

why not implement it in the configmanager? if it would be the right place?

@AndisGrossteins
Copy link
Contributor Author

why not implement it in the configmanager? if it would be the right place?

I wasn't sure how to approach it better. Now moved it into ConfigManager.

@Hirogen Hirogen requested a review from Copilot September 25, 2025 05:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an ArgumentException that occurs when the FontName specified in the configuration file is invalid, which was blocking application startup. The fix adds validation during configuration loading to detect invalid font names and fall back to the default monospace font.

Key Changes:

  • Added font name validation in the configuration loading process
  • Implemented fallback mechanism to default monospace font when validation fails
  • Added logging to inform users when font fallback occurs

Comment on lines 209 to 210
var fontFamily = new FontFamily(settings.Preferences.FontName);
settings.Preferences.FontName = fontFamily.Name;
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FontFamily instance is created but only used to validate the font name and get its canonical name. Consider disposing of the FontFamily instance or use a more efficient validation approach to avoid potential resource leaks.

Suggested change
var fontFamily = new FontFamily(settings.Preferences.FontName);
settings.Preferences.FontName = fontFamily.Name;
using (var fontFamily = new FontFamily(settings.Preferences.FontName))
{
settings.Preferences.FontName = fontFamily.Name;
}

Copilot uses AI. Check for mistakes.
Comment on lines 214 to 215
_logger.Warn($"Specified font '{settings.Preferences.FontName}' not found. Falling back to default: '{FontFamily.GenericMonospace.Name}'. {ex.Message}");
settings.Preferences.FontName = FontFamily.GenericMonospace.Name;
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FontFamily.GenericMonospace.Name is accessed multiple times (here and on line 215). Consider storing it in a variable to avoid repeated property access.

Suggested change
_logger.Warn($"Specified font '{settings.Preferences.FontName}' not found. Falling back to default: '{FontFamily.GenericMonospace.Name}'. {ex.Message}");
settings.Preferences.FontName = FontFamily.GenericMonospace.Name;
var genericMonospaceName = FontFamily.GenericMonospace.Name;
_logger.Warn($"Specified font '{settings.Preferences.FontName}' not found. Falling back to default: '{genericMonospaceName}'. {ex.Message}");
settings.Preferences.FontName = genericMonospaceName;

Copilot uses AI. Check for mistakes.
}
catch (ArgumentException ex)
{
_logger.Warn($"Specified font '{settings.Preferences.FontName}' not found. Falling back to default: '{FontFamily.GenericMonospace.Name}'. {ex.Message}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to log the exception in the warning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I'll add using to dispose of the FontFamily instance as suggested by Copilot.

Hirogen
Hirogen previously approved these changes Sep 25, 2025
using var fontFamily = new FontFamily(settings.Preferences.FontName);
settings.Preferences.FontName = fontFamily.Name;
}
catch (ArgumentException ex)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm a little nit picky here, but you can remove the "ex" variable, because we don't use it anyway :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. Let me just remove it, then.

@Hirogen Hirogen merged commit 2cf5a53 into LogExperts:Development Sep 25, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't start LogExpert if font in settings file is not found

2 participants