Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: log swallowed exceptions in core server components
Three silent catch blocks were hiding errors with no diagnostic info:

- TreeValuesCache.MigrateDatabaseV2: log sensorId when value deserialization
  fails during V2 migration instead of silently skipping the record
- AlertScheduleProvider.LoadSchedulesFromDb: log parse error and entity id/name
  when schedule parsing fails and fallback to raw entity is used
- TreeStateSnapshot ctor: add NLog logger and log deserialization error when
  state snapshot fails to load, instead of silently setting HasData=false

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
  • Loading branch information
lotgon and claude committed Mar 23, 2026
commit 581411e463b1763072164ebe881ae386954b2336
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ private void LoadSchedulesFromDatabase()
{
schedule = _parser.Parse(entity);
}
catch
catch (Exception ex)
{
_logger.Error(ex, $"Failed to parse alert schedule. Id = {entity.Id}, Name = {entity.Name}. Using raw entity as fallback.");
schedule = new AlertSchedule()
{
Id = new Guid(entity.Id),
Expand Down
3 changes: 2 additions & 1 deletion src/server/HSMServer.Core/Cache/TreeValuesCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1851,8 +1851,9 @@ private void MigrateDatabseV2()
{
val = sensor.ConvertFromJson(Encoding.UTF8.GetString(value));
}
catch
catch (Exception ex)
{
_logger.Error(ex, $"Failed to deserialize sensor value during V2 migration. SensorId = {sensorId}");
continue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using HSMDatabase.AccessManager;
using HSMDatabase.AccessManager.DatabaseEntities.SnapshotEntity;
using HSMServer.Core.DataLayer;
using NLog;
using System;
using System.Threading.Tasks;
using HSMServer.Core.TreeStateSnapshot.States;

namespace HSMServer.Core.TreeStateSnapshot
{
public sealed class TreeStateSnapshot : ITreeStateSnapshot
{
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

private readonly StateCollection<LastSensorState, SensorStateEntity> _sensors = new();
private readonly StateCollection<LastKeyState, LastKeyStateEntity> _keys = new();
private readonly ISnapshotDatabase _db;
Expand Down Expand Up @@ -35,8 +39,9 @@ public TreeStateSnapshot(IDatabaseCore db)

IsFinal = node.IsFinal;
}
catch
catch (Exception ex)
{
_logger.Error(ex, "Failed to deserialize tree state snapshot. Starting with empty state.");
HasData = false;
}
}
Expand Down
Loading