nextcloud / whiteboard

GNU Affero General Public License v3.0
2 stars 0 forks source link

Creating new files fails due to unparsable json #21

Closed juliushaertl closed 2 weeks ago

juliushaertl commented 1 month ago

A new file has empty content right now so fetching the file content fails as the empty string cannot be json_decoded.

We should also make the websocket_server catch this error to not crash

file:///Users/julius/repos/nextcloud/server/apps-extra/whiteboard/websocket_server/index.js:37
        throw new Error(`HTTP error! status: ${response.status}`)
              ^

Error: HTTP error! status: 500
    at getRoomDataFromFile (file:///Users/julius/repos/nextcloud/server/apps-extra/whiteboard/websocket_server/index.js:37:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Socket.<anonymous> (file:///Users/julius/repos/nextcloud/server/apps-extra/whiteboard/websocket_server/index.js:99:28)
{
  "reqId": "dDU0DBGSlwBCEGTLA0jX",
  "level": 3,
  "time": "2024-06-06T15:59:44+00:00",
  "remoteAddr": "192.168.65.1",
  "user": "admin",
  "app": "index",
  "method": "GET",
  "url": "/index.php/apps/whiteboard/367",
  "message": "Syntax error",
  "userAgent": "node-fetch",
  "version": "30.0.0.1",
  "exception": {
    "Exception": "JsonException",
    "Message": "Syntax error",
    "Code": 4,
    "Trace": [
      {
        "file": "/var/www/html/apps-extra/whiteboard/lib/Controller/WhiteboardController.php",
        "line": 40,
        "function": "json_decode",
        "args": [
          "",
          true,
          512,
          4194304
        ]
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 208,
        "function": "show",
        "class": "OCA\\Whiteboard\\Controller\\WhiteboardController",
        "type": "->",
        "args": [
          367
        ]
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 114,
        "function": "executeController",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [
          [
            "OCA\\Whiteboard\\Controller\\WhiteboardController"
          ],
          "show"
        ]
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/App.php",
        "line": 161,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [
          [
            "OCA\\Whiteboard\\Controller\\WhiteboardController"
          ],
          "show"
        ]
      },
      {
        "file": "/var/www/html/lib/private/Route/Router.php",
        "line": 309,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::",
        "args": [
          "OCA\\Whiteboard\\Controller\\WhiteboardController",
          "show",
          [
            "OC\\AppFramework\\DependencyInjection\\DIContainer"
          ],
          [
            "367",
            "whiteboard.whiteboard.show"
          ]
        ]
      },
      {
        "file": "/var/www/html/lib/base.php",
        "line": 988,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->",
        "args": [
          "/apps/whiteboard/367"
        ]
      },
      {
        "file": "/var/www/html/index.php",
        "line": 24,
        "function": "handleRequest",
        "class": "OC",
        "type": "::",
        "args": []
      }
    ],
    "File": "/var/www/html/apps-extra/whiteboard/lib/Controller/WhiteboardController.php",
    "Line": 40,
    "message": "Syntax error",
    "exception": {},
    "CustomMessage": "Syntax error"
  }
}
juliushaertl commented 1 month ago

I just noticed I pushed my potential fix already in https://github.com/nextcloud-gmbh/whiteboard/pull/29/files#diff-f1d3123a78f08c3e1345d35dcc52d627c991bb4ef34f28f10be60f4226442e95R40-R44

One thing I noticed was that we seem to only send back elements to the frontend in https://github.com/nextcloud-gmbh/whiteboard/blob/84c7ec62be9ed39ac668bf599390bb23cc9f972a/websocket_server/index.js#L43 so we might drop anything else in the json schema: https://docs.excalidraw.com/docs/codebase/json-schema Something we should probably address as well