]> source.dussan.org Git - nextcloud-server.git/commitdiff
Improve debugging for ServiceUnavailable exceptions
authorChris Wilson <chris+github@qwirx.com>
Tue, 6 Jan 2015 15:59:38 +0000 (15:59 +0000)
committerChris Wilson <chris+github@qwirx.com>
Tue, 6 Jan 2015 15:59:38 +0000 (15:59 +0000)
I was getting a lot of these in my logs for no apparent reason, and file
uploads were failing:

{"app":"webdav","message":"Sabre\\DAV\\Exception\\ServiceUnavailable: ","level":4,"time":"2015-01-06T15:33:39+00:00"}

In order to debug it, I had to add unique messages to all the places where
this exception was thrown, to identify which one it was, and that made the
logs much more useful:

{"app":"webdav","message":"Sabre\\DAV\\Exception\\ServiceUnavailable: Encryption is disabled","level":4,"time":"2015-01-06T15:36:47+00:00"}

lib/private/connector/sabre/file.php
lib/private/files/storage/dav.php

index cb03f30e023dbd5761704c023d9790c4321a42ed..76ebe3ed9fe8b1ba09464c3b80e3eeaac3ba8e3d 100644 (file)
@@ -56,12 +56,12 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
                                throw new \Sabre\DAV\Exception\Forbidden();
                        }
                } catch (\OCP\Files\StorageNotAvailableException $e) {
-                       throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
+                       throw new \Sabre\DAV\Exception\ServiceUnavailable("File is not updatable: ".$e->getMessage());
                }
 
                // throw an exception if encryption was disabled but the files are still encrypted
                if (\OC_Util::encryptedFiles()) {
-                       throw new \Sabre\DAV\Exception\ServiceUnavailable();
+                       throw new \Sabre\DAV\Exception\ServiceUnavailable("Encryption is disabled");
                }
 
                $fileName = basename($this->path);
@@ -107,7 +107,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
                } catch (\OCA\Files_Encryption\Exception\EncryptionException $e) {
                        throw new \Sabre\DAV\Exception\Forbidden($e->getMessage());
                } catch (\OCP\Files\StorageNotAvailableException $e) {
-                       throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
+                       throw new \Sabre\DAV\Exception\ServiceUnavailable("Failed to write file contents: ".$e->getMessage());
                }
 
                try {
@@ -147,7 +147,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
                        }
                        $this->refreshInfo();
                } catch (\OCP\Files\StorageNotAvailableException $e) {
-                       throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
+                       throw new \Sabre\DAV\Exception\ServiceUnavailable("Failed to check file size: ".$e->getMessage());
                }
 
                return '"' . $this->info->getEtag() . '"';
@@ -162,14 +162,14 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
 
                //throw exception if encryption is disabled but files are still encrypted
                if (\OC_Util::encryptedFiles()) {
-                       throw new \Sabre\DAV\Exception\ServiceUnavailable();
+                       throw new \Sabre\DAV\Exception\ServiceUnavailable("Encryption is disabled");
                } else {
                        try {
                                return $this->fileView->fopen(ltrim($this->path, '/'), 'rb');
                        } catch (\OCA\Files_Encryption\Exception\EncryptionException $e) {
                                throw new \Sabre\DAV\Exception\Forbidden($e->getMessage());
                        } catch (\OCP\Files\StorageNotAvailableException $e) {
-                               throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
+                               throw new \Sabre\DAV\Exception\ServiceUnavailable("Failed to open file: ".$e->getMessage());
                        }
                }
 
@@ -192,7 +192,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
                                throw new \Sabre\DAV\Exception\Forbidden();
                        }
                } catch (\OCP\Files\StorageNotAvailableException $e) {
-                       throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
+                       throw new \Sabre\DAV\Exception\ServiceUnavailable("Failed to unlink: ".$e->getMessage());
                }
 
                // remove properties
@@ -297,7 +297,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\
                                $info = $this->fileView->getFileInfo($targetPath);
                                return $info->getEtag();
                        } catch (\OCP\Files\StorageNotAvailableException $e) {
-                               throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
+                               throw new \Sabre\DAV\Exception\ServiceUnavailable("Failed to put file: ".$e->getMessage());
                        }
                }
 
index 887ec1972b3dc373aad952689628ca3ae406b7a0..355148de37aa05f6b1c9fdec226a974236ed3fa1 100644 (file)
@@ -529,7 +529,7 @@ class DAV extends \OC\Files\Storage\Common {
                } catch (Exception\NotFound $e) {
                        return false;
                } catch (Exception $e) {
-                       throw new StorageNotAvailableException();
+                       throw new StorageNotAvailableException(get_class($e).": ".$e->getMessage());
                }
        }
 }