Przeglądaj źródła

Fix OhmNvme error with resiliant updates

User received the following exception in their log:

```plain
System.NullReferenceException: Object reference not set to an instance of an object.
   at OhmGraphite.OhmNvme.Update()
```

So the code has been updated avoid eagerly deferencing objects that are
null.
Nick Babcock 3 lat temu
rodzic
commit
a5ea1fe903
1 zmienionych plików z 5 dodań i 5 usunięć
  1. 5 5
      OhmGraphite/OhmNvme.cs

+ 5 - 5
OhmGraphite/OhmNvme.cs

@@ -56,11 +56,11 @@ namespace OhmGraphite
 
         public void Update()
         {
-            var health = _nvme.Smart.GetHealthInfo();
-            ErrorInfoLogEntryCount.Value = health.ErrorInfoLogEntryCount;
-            MediaErrors.Value = health.MediaErrors;
-            PowerCycles.Value = health.PowerCycle;
-            UnsafeShutdowns.Value = health.UnsafeShutdowns;
+            var health = _nvme?.Smart?.GetHealthInfo();
+            ErrorInfoLogEntryCount.Value = health?.ErrorInfoLogEntryCount;
+            MediaErrors.Value = health?.MediaErrors;
+            PowerCycles.Value = health?.PowerCycle;
+            UnsafeShutdowns.Value = health?.UnsafeShutdowns;
         }
     }
 }