Repository: syncthing/syncthing (language: go)

Issue:
TypeError: Cannot read properties of null (reading 'status') in the GUI after killing Syncthing
I keep getting these errors while accessing the Web GUI remotely. This usually happens after Syncthing has been killed on the remote device, e.g. when restarting the computer there. The problem can be reproduced locally, e.g. by killing the Syncthing process (instead of shutting it down gracefully using the GUI, etc.)

To reproduce:

1. Open the Web GUI in a browser.
2. Kill the Syncthing process (e.g. using the Task Manager in Windows).
3. Wait a few seconds.
4. The GUI now displays the following error message:

   ![image](https://user-images.githubusercontent.com/5626656/162541958-420b034a-b035-4c45-a759-bec72e57add8.png)

   ```
   TypeError: Cannot read properties of null (reading 'status')
       at syncthingController.js:182:25
       at Scope.$emit (angular.js:14835:33)
       at $scope.emitHTTPError (syncthingController.js:425:20)
       at angular.js:9461:11
       at processQueue (angular.js:13337:27)
       at angular.js:13353:27
       at Scope.$eval (angular.js:14589:28)
       at Scope.$digest (angular.js:14405:31)
       at Scope.$apply (angular.js:14694:24)
       at angular.js:14984:22
   ```
TypeError: Cannot read properties of null (reading 'status') in the GUI after killing Syncthing
I keep getting these errors while accessing the Web GUI remotely. This usually happens after Syncthing has been killed on the remote device, e.g. when restarting the computer there. The problem can be reproduced locally, e.g. by killing the Syncthing process (instead of shutting it down gracefully using the GUI, etc.)

To reproduce:

1. Open the Web GUI in a browser.
2. Kill the Syncthing process (e.g. using the Task Manager in Windows).
3. Wait a few seconds.
4. The GUI now displays the following error message:

   ![image](https://user-images.githubusercontent.com/5626656/162541958-420b034a-b035-4c45-a759-bec72e57add8.png)

   ```
   TypeError: Cannot read properties of null (reading 'status')
       at syncthingController.js:182:25
       at Scope.$emit (angular.js:14835:33)
       at $scope.emitHTTPError (syncthingController.js:425:20)
       at angular.js:9461:11
       at processQueue (angular.js:13337:27)
       at angular.js:13353:27
       at Scope.$eval (angular.js:14589:28)
       at Scope.$digest (angular.js:14405:31)
       at Scope.$apply (angular.js:14694:24)
       at angular.js:14984:22
   ```


Discussion / hints:
I'd like to add that this problem isn't limited to what I originally wrote. If you try to enable/disable HTTPS in the GUI, it also displays the same error, which is actually more serious then, because it seems to prevent the GUI from triggering a refresh. The error is present when changing themes too, but there the GUI does refresh successfully, so it's only visible for a brief moment.
I'd like to add that this problem isn't limited to what I originally wrote. If you try to enable/disable HTTPS in the GUI, it also displays the same error, which is actually more serious then, because it seems to prevent the GUI from triggering a refresh. The error is present when changing themes too, but there the GUI does refresh successfully, so it's only visible for a brief moment.

Fix patch:
diff --git a/gui/default/syncthing/core/syncthingController.js b/gui/default/syncthing/core/syncthingController.js
index 7e72a67b671..77c1910dbf9 100755
--- a/gui/default/syncthing/core/syncthingController.js
+++ b/gui/default/syncthing/core/syncthingController.js
@@ -178,7 +178,8 @@ angular.module('syncthing.core')
 
             console.log('HTTPError', arg);
             online = false;
-            if (!restarting) {
+            // We sometimes get arg == null from angularjs - no idea why
+            if (!restarting && arg) {
                 if (arg.status === 0) {
                     // A network error, not an HTTP error
                     $scope.$emit(Events.OFFLINE);


Test patch: