Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: basicOperation(): Argument #2 ($path) must be of type string, null given #40090

Closed
5 of 8 tasks
simonspa opened this issue Aug 29, 2023 · 55 comments · Fixed by #42891
Closed
5 of 8 tasks

[Bug]: basicOperation(): Argument #2 ($path) must be of type string, null given #40090

simonspa opened this issue Aug 29, 2023 · 55 comments · Fixed by #42891
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 27-feedback bug feature: filesystem feature: versions

Comments

@simonspa
Copy link
Contributor

⚠️ This issue respects the following points: ⚠️

Bug description

Yesterday, the below stack trace appeared several hundred times in my Nextcloud 27.0.2 log. From the trace I infer that user BBBB shared an ODS file with user AAAA and the latter is trying to open it (or save it? The user agent is "COOLWSD".)

Whatever is happening, in the end a method requests a string but obtains null.

Steps to reproduce

(log entries)

Expected behavior

The requested operation succeeds.

Installation method

Community Manual installation with Archive

Nextcloud Server version

27

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.1

Web server

Nginx

Database engine version

MariaDB

Is this bug present after an update or on a fresh install?

Upgraded to a MAJOR version (ex. 22 to 23)

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?

  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other

Configuration report

{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "my.domain.tld"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "data-fingerprint": "58897020af7835d5d5eebe9f70033c28",
        "dbtype": "mysql",
        "version": "27.0.2.1",
        "overwrite.cli.url": "https:\/\/my.domain.tld",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "3306",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "htaccess.RewriteBase": "\/",
        "mail_smtpsecure": "ssl",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "465",
        "log_rotate_size": "104857600",
        "mail_smtpauthtype": "LOGIN",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 0,
            "password": "***REMOVED SENSITIVE VALUE***",
            "timeout": 0
        },
        "memcache.local": "\\OC\\Memcache\\APCu",
        "maintenance": false,
        "preview_max_y": 2048,
        "preview_max_x": 2048,
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "mail_smtpauth": 1,
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "knowledgebaseenabled": false,
        "loglevel": 2,
        "filelocking.enabled": "true",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "updater.release.channel": "stable",
        "activity_expire_days": 90,
        "mail_smtpmode": "smtp",
        "theme": "",
        "trusted_proxies": "***REMOVED SENSITIVE VALUE***",
        "app_install_overwrite": [
            "files_downloadactivity"
        ],
        "memcache.distributed": "\\OC\\Memcache\\Redis",
    }
}

List of activated Apps

Enabled:
  - activity: 2.19.0
  - admin_audit: 1.17.0
  - bookmarks: 13.1.1
  - bruteforcesettings: 2.7.0
  - calendar: 4.4.4
  - cloud_federation_api: 1.10.0
  - comments: 1.17.0
  - contacts: 5.3.2
  - contactsinteraction: 1.8.0
  - dashboard: 7.7.0
  - dav: 1.27.0
  - event_update_notification: 2.2.0
  - federatedfilesharing: 1.17.0
  - federation: 1.17.0
  - files: 1.22.0
  - files_downloadactivity: 1.16.0
  - files_pdfviewer: 2.8.0
  - files_rightclick: 1.6.0
  - files_sharing: 1.19.0
  - files_trashbin: 1.17.0
  - files_versions: 1.20.0
  - logreader: 2.12.0
  - lookup_server_connector: 1.15.0
  - metadata: 0.19.0
  - notes: 4.8.1
  - notifications: 2.15.0
  - notify_push: 0.6.3
  - oauth2: 1.15.1
  - password_policy: 1.17.0
  - passwords: 2023.8.31
  - photos: 2.3.0
  - previewgenerator: 5.3.0
  - privacy: 1.11.0
  - provisioning_api: 1.17.0
  - quota_warning: 1.17.0
  - richdocuments: 8.1.1
  - serverinfo: 1.17.0
  - settings: 1.9.0
  - sharebymail: 1.17.0
  - spreed: 17.0.3
  - tasks: 0.15.0
  - text: 3.8.0
  - theming: 2.2.0
  - theming_customcss: 1.14.0
  - twofactor_backupcodes: 1.16.0
  - twofactor_totp: 9.0.0
  - twofactor_webauthn: 1.2.0
  - updatenotification: 1.17.0
  - user_migration: 4.0.1
  - user_status: 1.7.0
  - viewer: 2.1.0
  - weather_status: 1.7.0
  - workflowengine: 2.9.0
Disabled:
  - circles: 27.0.1 (installed 25.0.0)
  - encryption: 2.15.0
  - files_external: 1.19.0 (installed 1.10.0)
  - firstrunwizard: 2.16.0 (installed 2.9.0)
  - nextcloud_announcements: 1.16.0 (installed 1.5.0)
  - recommendations: 1.6.0 (installed 0.4.0)
  - related_resources: 1.2.0 (installed 1.0.3)
  - support: 1.10.0 (installed 1.0.0)
  - survey_client: 1.15.0 (installed 0.1.5)
  - systemtags: 1.17.0 (installed 1.15.0)
  - user_ldap: 1.17.0

Nextcloud Signing status

No errors have been found.

Nextcloud Logs

{
    "reqId": "PoA62VVnraMBqx6nXJ1e",
    "level": 3,
    "time": "2023-08-28T22:49:24+02:00",
    "remoteAddr": "2a03:4000:2:bc5::1",
    "user": "AAAA",
    "app": "index",
    "method": "POST",
    "url": "/index.php/apps/richdocuments/wopi/files/5040041_oc0e7rzi20xo/contents?access_token=MCqDcyRRHu2FoEazjmUCoxqKnLEVgh4G&access_token_ttl=1693289762000",
    "message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 518 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1110",
    "userAgent": "COOLWSD HTTP Agent 23.05.2.2",
    "version": "27.0.2.1",
    "exception":
    {
        "Exception": "Exception",
        "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 518 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1110",
        "Code": 0,
        "Trace":
        [
            {
                "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
                "line": 183,
                "function": "dispatch",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->",
                "args":
                [
                    [
                        "OCA\\Richdocuments\\Controller\\WopiController"
                    ],
                    "putFile"
                ]
            },
            {
                "file": "/var/www/nextcloud/lib/private/Route/Router.php",
                "line": 315,
                "function": "main",
                "class": "OC\\AppFramework\\App",
                "type": "::",
                "args":
                [
                    "OCA\\Richdocuments\\Controller\\WopiController",
                    "putFile",
                    [
                        "OC\\AppFramework\\DependencyInjection\\DIContainer"
                    ],
                    [
                        "5040041_oc0e7rzi20xo",
                        "richdocuments.wopi.putFile"
                    ]
                ]
            },
            {
                "file": "/var/www/nextcloud/lib/base.php",
                "line": 1071,
                "function": "match",
                "class": "OC\\Route\\Router",
                "type": "->",
                "args":
                [
                    "/apps/richdocuments/wopi/files/5040041_oc0e7rzi20xo/contents"
                ]
            },
            {
                "file": "/var/www/nextcloud/index.php",
                "line": 36,
                "function": "handleRequest",
                "class": "OC",
                "type": "::",
                "args":
                []
            }
        ],
        "File": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
        "Line": 169,
        "Previous":
        {
            "Exception": "TypeError",
            "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 518",
            "Code": 0,
            "Trace":
            [
                {
                    "file": "/var/www/nextcloud/lib/private/Files/View.php",
                    "line": 518,
                    "function": "basicOperation",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args":
                    [
                        "file_exists",
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Filesystem.php",
                    "line": 545,
                    "function": "file_exists",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args":
                    [
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/files_versions/lib/Storage.php",
                    "line": 189,
                    "function": "file_exists",
                    "class": "OC\\Files\\Filesystem",
                    "type": "::",
                    "args":
                    [
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
                    "line": 210,
                    "function": "store",
                    "class": "OCA\\Files_Versions\\Storage",
                    "type": "::",
                    "args":
                    [
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
                    "line": 107,
                    "function": "write_hook",
                    "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                    "type": "->",
                    "args":
                    [
                        [
                            "OC\\Files\\Node\\File"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/EventDispatcher/ServiceEventListener.php",
                    "line": 86,
                    "function": "handle",
                    "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                    "line": 251,
                    "function": "__invoke",
                    "class": "OC\\EventDispatcher\\ServiceEventListener",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ],
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent",
                        [
                            "Symfony\\Component\\EventDispatcher\\EventDispatcher"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                    "line": 73,
                    "function": "callListeners",
                    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args":
                    [
                        [
                            [
                                "Closure"
                            ]
                        ],
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent",
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
                    "line": 94,
                    "function": "dispatch",
                    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ],
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
                    "line": 106,
                    "function": "dispatch",
                    "class": "OC\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args":
                    [
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent",
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Node/HookConnector.php",
                    "line": 112,
                    "function": "dispatchTyped",
                    "class": "OC\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/legacy/OC_Hook.php",
                    "line": 105,
                    "function": "write",
                    "class": "OC\\Files\\Node\\HookConnector",
                    "type": "->",
                    "args":
                    [
                        [
                            "/Documents/SomeDocuments.ods",
                            true
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/View.php",
                    "line": 588,
                    "function": "emit",
                    "class": "OC_Hook",
                    "type": "::",
                    "args":
                    [
                        "OC_Filesystem",
                        "write",
                        [
                            "/Documents/SomeDocument.ods",
                            true
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/View.php",
                    "line": 629,
                    "function": "emit_file_hooks_pre",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args":
                    [
                        true,
                        "/BBBB/files/Documents/SomeDocument.ods",
                        true
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Node/File.php",
                    "line": 73,
                    "function": "file_put_contents",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args":
                    [
                        "/BBBB/files/Documents/SomeDocument.ods",
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 504,
                    "function": "putContent",
                    "class": "OC\\Files\\Node\\File",
                    "type": "->",
                    "args":
                    [
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 786,
                    "function": "OCA\\Richdocuments\\Controller\\{closure}",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args":
                    [
                        "*** sensitive parameters replaced ***"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 763,
                    "function": "retryOperation",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args":
                    [
                        [
                            "Closure"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Lock/LockManager.php",
                    "line": 29,
                    "function": "OCA\\Richdocuments\\Controller\\{closure}",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args":
                    [
                        "*** sensitive parameters replaced ***"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 766,
                    "function": "runInScope",
                    "class": "OC\\Files\\Lock\\LockManager",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCP\\Files\\Lock\\LockContext"
                        ],
                        [
                            "Closure"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 505,
                    "function": "wrappedFilesystemOperation",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCA\\Richdocuments\\Db\\Wopi",
                            308
                        ],
                        [
                            "Closure"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 230,
                    "function": "putFile",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args":
                    [
                        "5040041",
                        "MCqDcyRRHu2FoEazjmUCoxqKnLEVgh4G"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 137,
                    "function": "executeController",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCA\\Richdocuments\\Controller\\WopiController"
                        ],
                        "putFile"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
                    "line": 183,
                    "function": "dispatch",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCA\\Richdocuments\\Controller\\WopiController"
                        ],
                        "putFile"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Route/Router.php",
                    "line": 315,
                    "function": "main",
                    "class": "OC\\AppFramework\\App",
                    "type": "::",
                    "args":
                    [
                        "OCA\\Richdocuments\\Controller\\WopiController",
                        "putFile",
                        [
                            "OC\\AppFramework\\DependencyInjection\\DIContainer"
                        ],
                        [
                            "5040041_oc0e7rzi20xo",
                            "richdocuments.wopi.putFile"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/base.php",
                    "line": 1071,
                    "function": "match",
                    "class": "OC\\Route\\Router",
                    "type": "->",
                    "args":
                    [
                        "/apps/richdocuments/wopi/files/5040041_oc0e7rzi20xo/contents"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/index.php",
                    "line": 36,
                    "function": "handleRequest",
                    "class": "OC",
                    "type": "::",
                    "args":
                    []
                }
            ],
            "File": "/var/www/nextcloud/lib/private/Files/View.php",
            "Line": 1110
        },
        "CustomMessage": "--"
    },
    "id": "64ed996b3fa81"
}

Additional info

No response

@simonspa simonspa added bug 0. Needs triage Pending check for reproducibility or if it fits our roadmap labels Aug 29, 2023
@bjo81
Copy link

bjo81 commented Sep 4, 2023

@simonspa Do you also expierence the issue that COOL is unable to save the document then? In our case a user creates a file in COOL, but when he want's to save it, the issue appears.

@simonspa
Copy link
Contributor Author

simonspa commented Sep 5, 2023

That's a good question @bjo81 that I unfortunately cannot really answer. This only happened in other user sessions so far and I have only observed the above message in the log. I don't know how the UX is in that moment. I will try to inquire with them but since it's been a few days they might not remember.

@SystemKeeper
Copy link
Contributor

I've seen this as well and thought it was an issue in the richdocuments app at first (see nextcloud/richdocuments#3169), but it looks like it's something with the files_version app.

In my case the file in question was shared from a groupfolder, but looking at the enabled apps above, groupfolders are not enabled on your installation, is that correct? So in that case, I can remove groupfolders as the responsible app in my thinking.

The error does appear when the user tries to save a (shared with him) document. Sometimes a message pops up saying something about missing permissions and unable to save. The changes are then lost.

I've seen this on 27.0.2 and also on 27.1 RC2.

Also CC @artonge

@simonspa
Copy link
Contributor Author

I can definitely confirm that I do not have the group folders app enabled.

@SystemKeeper
Copy link
Contributor

I am wondering if the try-catch is enough here:

try {
return $this->rootFolder
->getUserFolder(\OC_User::getUser())
->getRelativePath($node->getPath());
} catch (\Throwable $ex) {
return $this->rootFolder
->getUserFolder($node->getOwner()->getUid())
->getRelativePath($node->getPath());
}

if I understand correctly, this calls getRelativePath from OC\Files\Utils\PathHelper (?) but this can return null instead of throwing an exception?

if ($path === $root) {
return '/';
} elseif (!str_starts_with($path, $root . '/')) {
return null;
} else {
$path = substr($path, strlen($root));
return self::normalizePath($path);
}

But that's just blind guessing on my end since I am not familiar with the code. On my testinstance I have disabled files_versions app for now and it seems to work fine now... Let's see.

@AIlkiv
Copy link
Contributor

AIlkiv commented Oct 2, 2023

@artonge Hi. Can you please take a look?

There is a method OCA\Files_Versions\Listener\FileEventsListener::getPathForNode, and it appears that you have created it (commit: 3da63f4).

I have studied the operation of this method, and I believe it would make sense to remove the exception handling from it.

Why?

Example 1

Alice has the file Alice\files\study\homework.odt (file in folder).
She shared this file with Bob.
Bob is editing this file.
When saved, $node->getPath() in the getPathForNode method will have the value "Bob\files\homework.odt".
If it was not possible to connect to the Bob folder.
Will try to get RelativePath from Bob\files\homework.odt relative to Alice\files and it will return null
As a result, we will get the error that the author of this issue complains about.

Example 2

I thought it would make sense to rewrite the exception handling:

$ownerFolder = $this->rootFolder->getUserFolder($node->getOwner()->getUid());
$ownerNode = $ownerFolder->getById($node->getId());

return $ownerFolder->getRelativePath($ownerNode ->getPath());

\study\homework.odt will then be returned

And then in the OCA\Files_Versions\Store::store method there is a Filesystem::file_exists($filename) check against Bob (he has \homework.odt, not \study\homework.odt). As a result, Store::store will not work correctly.

Based on these two cases, I have the impression that the system will work more smoothly without handling this exception.

} catch (\Throwable $ex) {
    return $this->rootFolder
        ->getUserFolder($node->getOwner()->getUid())
        ->getRelativePath($node->getPath());
}

But I have relatively recently started studying Nextcloud, so I would be very grateful if you could evaluate the correctness of these conclusions.

@jolly-jump
Copy link

jolly-jump commented Oct 5, 2023

Hi @AIlkiv
I do barely understand, what you are doing. But I was desperately in need of a solution and used your rewrite: it works for me (!).
You don't need the second line, though? $ownerNode will not be used in the following lines.
Cheers,
Tobias

@jolly-jump
Copy link

I've seen this on 27.0.2 and also on 27.1 RC2.

Also CC @artonge

Beside myself having the problem: see here I found another user from long time/version ago: https://help.nextcloud.com/t/collabora-on-mobile-cant-save-edited-documents-in-shared-folders/69272/2
Even if the bug is not that old, is there a chance to get this fixed without having to disable files_versions ?

@AIlkiv
Copy link
Contributor

AIlkiv commented Oct 6, 2023

I do barely understand, what you are doing. But I was desperately in need of a solution and used your rewrite: it works for me (!).
You don't need the second line, though? $ownerNode will not be used in the following lines.

This is not a solution. It should not be used.

There was a mistake, I corrected the comment return $ownerFolder->getRelativePath($ownerNode->getPath());.

@jolly-jump
Copy link

Hi @AIlkiv ,
thanks for the correction.
However, I tried a couple of things and the main problem is indeed that getRelativePath() is empty - iff the path of the node does not fit to the current user.

So, from where my problem comes: $node->getPath() is already Alice\files\study\homework.odt . This seems to be a problem steming from the richdocuments-App.... the same thing in the browser, and $node->getPath() is Bob\...

And one more thing: your proposal does not work, since $ownerFolder->getById($node->getId()) returns an array of possible Nodes/Folders. One would have to adjust this atleast.

I have used this workaround now:

        private function getPathForNode(Node $node): ?string {
                $ownerFolder = $this->rootFolder->getUserFolder($node->getOwner()->getUid());
                try {   
                        $relativepath = $this->rootFolder
                                ->getUserFolder(\OC_User::getUser())
                                ->getRelativePath($node->getPath());
                        if ($relativepath === null) {
                                $this->logger->error('Relative Path null of Node Path: ' . $node->getPath() . '; User: ' . \OC_User::getUser());
                                $relativepath = $ownerFolder->getRelativePath($node->getPath());
                        }
                } catch (\Throwable $ex) {
                        $relativepath = $ownerFolder->getRelativePath($node->getPath());
                }
                return $relativepath;
        }

@AIlkiv
Copy link
Contributor

AIlkiv commented Oct 6, 2023

@jolly-jump In which case path may not be from the current user?

I checked the following situations:

  1. when editing its own file.
  2. when editing a shared file.

In both cases, I had the correct path.

@jolly-jump
Copy link

@AIlkiv

I am talking about the situation, where bob edits a file shared from alice.

  • When bob uses the Nextcloud-App to open a document with collabora and saves it (or closes it).
    Then: the \OC_User::getUser() = "bob" and the $node->getPath() = /alice/files/study/homework.odt (the $ownerNode->getPath() is obviously the same

  • When opening the same file in the browser by bob:
    Then: the \OC_User::getUser() = bob and the $node->getPath() = /bob/files/homework.odt, the $ownerNode returns the path in Alices acount.

I admit, I haven't tested a subdirectory like "study" in the account of Alice.

Thus: for the webediting everything works already out of the box (the try-part of the exception handling works). For the mobile editing part, the try-part works as well and does not throw an exception, but the relativePath-string is "null", since $node is already the "$ownerNode".

Thus the "catch"-part is never reached (in these two situations).

@kyrofa
Copy link
Member

kyrofa commented Dec 2, 2023

I get this error trying to run encryption:encrypt-all:

$ php occ encryption:encrypt-all"
You are about to encrypt all files stored in your Nextcloud installation.
Depending on the number of available files, and their size, this may take quite some time.
Please ensure that no user accesses their files during this time!
Note: The encryption module you use determines which files get encrypted.

Do you really want to continue? (y/n) y


Encrypt all files with the Default encryption module
====================================================


Create key-pair for every user
------------------------------

This module will encrypt all files in the users files folder initially.
Already existing versions and files in the trash bin will not be encrypted.



 Key-pair created for all users 
 [->--------------------------]

Generated encryption key passwords
----------------------------------


All users already had a key-pair, no further action needed.



Start to encrypt users files
----------------------------



 %message% 
 [>---------------------------]An unhandled exception has been thrown:
TypeError: OC\Files\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/html/lib/private/Files/View.php on line 528 and defined in /var/www/html/lib/private/Files/View.php:1128
Stack trace:
#0 /var/www/html/lib/private/Files/View.php(528): OC\Files\View->basicOperation('file_exists', NULL)
#1 /var/www/html/apps/files_versions/lib/Listener/FileEventsListener.php(345): OC\Files\View->file_exists(NULL)
#2 /var/www/html/apps/files_versions/lib/Listener/FileEventsListener.php(132): OCA\Files_Versions\Listener\FileEventsListener->pre_renameOrCopy_hook(Object(OC\Files\Node\File), Object(OC\Files\Node\File))
#3 /var/www/html/lib/private/EventDispatcher/ServiceEventListener.php(86): OCA\Files_Versions\Listener\FileEventsListener->handle(Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent))
#4 /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php(251): OC\EventDispatcher\ServiceEventListener->__invoke(Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent), 'OCP\\Files\\Event...', Object(Symfony\Component\EventDispatcher\EventDispatcher))
#5 /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php(73): Symfony\Component\EventDispatcher\EventDispatcher->callListeners(Array, 'OCP\\Files\\Event...', Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent))
#6 /var/www/html/lib/private/EventDispatcher/EventDispatcher.php(94): Symfony\Component\EventDispatcher\EventDispatcher->dispatch(Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent), 'OCP\\Files\\Event...')
#7 /var/www/html/lib/private/EventDispatcher/EventDispatcher.php(106): OC\EventDispatcher\EventDispatcher->dispatch('OCP\\Files\\Event...', Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent))
#8 /var/www/html/lib/private/Files/Node/HookConnector.php(187): OC\EventDispatcher\EventDispatcher->dispatchTyped(Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent))
#9 /var/www/html/lib/private/legacy/OC_Hook.php(105): OC\Files\Node\HookConnector->rename(Array)
#10 /var/www/html/lib/private/Files/View.php(760): OC_Hook::emit('OC_Filesystem', 'rename', Array)
#11 /var/www/html/apps/encryption/lib/Crypto/EncryptAll.php(302): OC\Files\View->rename('/christopher@mi...', '/christopher@mi...')
#12 /var/www/html/apps/encryption/lib/Crypto/EncryptAll.php(274): OCA\Encryption\Crypto\EncryptAll->encryptFile('/christopher@mi...')
#13 /var/www/html/apps/encryption/lib/Crypto/EncryptAll.php(222): OCA\Encryption\Crypto\EncryptAll->encryptUsersFiles('christopher@mir...', Object(Symfony\Component\Console\Helper\ProgressBar), 'christopher@mir...')
#14 /var/www/html/apps/encryption/lib/Crypto/EncryptAll.php(168): OCA\Encryption\Crypto\EncryptAll->encryptAllUsersFiles()
#15 /var/www/html/apps/encryption/lib/Crypto/Encryption.php(551): OCA\Encryption\Crypto\EncryptAll->encryptAll(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/html/core/Command/Encryption/EncryptAll.php(116): OCA\Encryption\Crypto\Encryption->encryptAll(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/html/3rdparty/symfony/console/Command/Command.php(298): OC\Core\Command\Encryption\EncryptAll->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /var/www/html/3rdparty/symfony/console/Application.php(1040): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /var/www/html/3rdparty/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand(Object(OC\Core\Command\Encryption\EncryptAll), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /var/www/html/3rdparty/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /var/www/html/lib/private/Console/Application.php(211): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /var/www/html/console.php(100): OC\Console\Application->run()
#23 /var/www/html/occ(11): require_once('/var/www/html/c...')
#24 {main}command terminated with exit code 1

Any idea what's happening, here?

@jakobroehrl
Copy link

When I disable the version app, the problem is solved.
The version of the version app is 1.20.0
Is this solved in a newer version?

@artonge
Copy link
Contributor

artonge commented Dec 14, 2023

Could one of you, that experience the issue, apply the following patch and check what kind of file causes the issue for them?
This will create a log when getPathForNode return a null value.

null_path_files_versions_hook.txt

@SystemKeeper
Copy link
Contributor

Applied the patch and re-enabled files_versions. Lets see. I was unable to reproduce it on purpose, only when someone complained that the data they entered in Nextcloud Office was lost.

@jakobroehrl Is it reproducable for you each time?

@SystemKeeper
Copy link
Contributor

That was fast, logged the error below. Just to mention it, this happens for me when trying to edit a shared document from the iOS Files app. And I see that @jakobroehrl linked to the Android app. Maybe there's something different when opening richdocuments in a webview in contrast to accessing it through the nextcloud UI?

{
    "reqId": "OBWbUL7unF4Oo5oYPnws",
    "level": 3,
    "time": "2023-12-14T17:50:50+01:00",
    "remoteAddr": "172.30.150.2",
    "user": "test",
    "app": "richdocuments",
    "method": "POST",
    "url": "//index.php/apps/richdocuments/wopi/files/866619_oc4r8rpp6vq8/contents?access_token=....&access_token_ttl=1702608560000",
    "message": see below
    "userAgent": "COOLWSD HTTP Agent 23.05.5.4",
    "version": "28.0.0.11"
}

Exception:

{
    "Exception": "Exception",
    "Message": "Object of class OC\\User\\LazyUser could not be converted to string in file '/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php' line 197",
    "Code": 0,
    "Trace": [
        {
            "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
            "line": 184,
            "function": "dispatch",
            "class": "OC\\AppFramework\\Http\\Dispatcher",
            "type": "->"
        },
        {
            "file": "/var/www/nextcloud/lib/private/Route/Router.php",
            "line": 315,
            "function": "main",
            "class": "OC\\AppFramework\\App",
            "type": "::"
        },
        {
            "file": "/var/www/nextcloud/lib/base.php",
            "line": 1069,
            "function": "match",
            "class": "OC\\Route\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/nextcloud/index.php",
            "line": 39,
            "function": "handleRequest",
            "class": "OC",
            "type": "::"
        }
    ],
    "File": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
    "Line": 169,
    "Previous": {
        "Exception": "Error",
        "Message": "Object of class OC\\User\\LazyUser could not be converted to string",
        "Code": 0,
        "Trace": [
            {
                "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
                "line": 102,
                "function": "write_hook",
                "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/EventDispatcher/ServiceEventListener.php",
                "line": 86,
                "function": "handle",
                "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                "line": 230,
                "function": "__invoke",
                "class": "OC\\EventDispatcher\\ServiceEventListener",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                "line": 59,
                "function": "callListeners",
                "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
                "line": 94,
                "function": "dispatch",
                "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
                "line": 106,
                "function": "dispatch",
                "class": "OC\\EventDispatcher\\EventDispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Files/Node/HookConnector.php",
                "line": 100,
                "function": "dispatchTyped",
                "class": "OC\\EventDispatcher\\EventDispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/legacy/OC_Hook.php",
                "line": 105,
                "function": "write",
                "class": "OC\\Files\\Node\\HookConnector",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Files/View.php",
                "line": 596,
                "function": "emit",
                "class": "OC_Hook",
                "type": "::"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Files/View.php",
                "line": 639,
                "function": "emit_file_hooks_pre",
                "class": "OC\\Files\\View",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Files/Node/File.php",
                "line": 73,
                "function": "file_put_contents",
                "class": "OC\\Files\\View",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                "line": 512,
                "function": "putContent",
                "class": "OC\\Files\\Node\\File",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                "line": 804,
                "function": "OCA\\Richdocuments\\Controller\\{closure}",
                "class": "OCA\\Richdocuments\\Controller\\WopiController",
                "type": "->",
                "args": [
                    "*** sensitive parameters replaced ***"
                ]
            },
            {
                "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                "line": 781,
                "function": "retryOperation",
                "class": "OCA\\Richdocuments\\Controller\\WopiController",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Files/Lock/LockManager.php",
                "line": 39,
                "function": "OCA\\Richdocuments\\Controller\\{closure}",
                "class": "OCA\\Richdocuments\\Controller\\WopiController",
                "type": "->",
                "args": [
                    "*** sensitive parameters replaced ***"
                ]
            },
            {
                "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                "line": 784,
                "function": "runInScope",
                "class": "OC\\Files\\Lock\\LockManager",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                "line": 511,
                "function": "wrappedFilesystemOperation",
                "class": "OCA\\Richdocuments\\Controller\\WopiController",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
                "line": 230,
                "function": "putFile",
                "class": "OCA\\Richdocuments\\Controller\\WopiController",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
                "line": 137,
                "function": "executeController",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
                "line": 184,
                "function": "dispatch",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Route/Router.php",
                "line": 315,
                "function": "main",
                "class": "OC\\AppFramework\\App",
                "type": "::"
            },
            {
                "file": "/var/www/nextcloud/lib/base.php",
                "line": 1069,
                "function": "match",
                "class": "OC\\Route\\Router",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/index.php",
                "line": 39,
                "function": "handleRequest",
                "class": "OC",
                "type": "::"
            }
        ],
        "File": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
        "Line": 197
    },
    "message": "Uncaught error: Object of class OC\\User\\LazyUser could not be converted to string in file '/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php' line 197",
    "exception": {},
    "CustomMessage": "Uncaught error: Object of class OC\\User\\LazyUser could not be converted to string in file '/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php' line 197"
}

@artonge
Copy link
Contributor

artonge commented Dec 14, 2023

Ah, forgot to add ->getUID() at the end 🙈. Sorry, can you try again with this patch?

null_path_files_versions_hook.txt

@kyrofa
Copy link
Member

kyrofa commented Dec 14, 2023

When I disable the version app, the problem is solved.

Thank you for this @jakobroehrl, that's allowing me to actually encrypt files.

@SystemKeeper
Copy link
Contributor

Sorry, can you try again with this patch?

Sure 👍

Here you go:

With "marcel.mueller" being the user who shared the file and "test" the user who tried to edit on an iPhone.

{
    "reqId": "mhRiDveSa3WjEDte4j6D",
    "level": 3,
    "time": "2023-12-14T18:08:41+01:00",
    "remoteAddr": "172.30.150.2",
    "user": "test",
    "app": "files_versions",
    "method": "POST",
    "url": "//index.php/apps/richdocuments/wopi/files/866619_oc4r8rpp6vq8/contents?access_token=...&access_token_ttl=1702609577000",
    "message": "Failed to find relative path for file for /marcel.mueller/files/Gesch\u00e4ftsleitung/SubFolder/File.xlsx and owner test",
    "userAgent": "COOLWSD HTTP Agent 23.05.5.4",
    "version": "28.0.0.11",
    "data": {
        "app": "files_versions"
    }
}

@SystemKeeper
Copy link
Contributor

For testing I moved the logging part to the outside of the if, so it's logged in all cases.

When I log in as user "test" and edit the file in Web, this happens:

{
    "reqId": "lB7HzB0OuD1lzetbfqqW",
    "level": 3,
    "time": "2023-12-14T20:28:36+01:00",
    "remoteAddr": "172.30.150.2",
    "user": "test",
    "app": "files_versions",
    "method": "POST",
    "url": "//index.php/apps/richdocuments/wopi/files/866619_oc4r8rpp6vq8/contents?access_token=....&access_token_ttl=0",
    "message": "Found relative path for file for /test/files/SharedFolder/File.xlsx and owner marcel.mueller",
    "userAgent": "COOLWSD HTTP Agent 23.05.5.4",
    "version": "28.0.0.11",
    "data": {
        "app": "files_versions"
    }
}

When I edit the same file on iOS this happens (still user "test"):

{
    "reqId": "BweWs7paOuwiU9WQRbL2",
    "level": 3,
    "time": "2023-12-14T20:29:11+01:00",
    "remoteAddr": "172.30.150.2",
    "user": "test",
    "app": "files_versions",
    "method": "POST",
    "url": "//index.php/apps/richdocuments/wopi/files/866619_oc4r8rpp6vq8/contents?access_token=....&access_token_ttl=1702618112000&permission=edit",
    "message": "Failed to find relative path for file for /marcel.mueller/files/Gesch\u00e4ftsleitung/SharedFolder/File.xlsx and owner test",
    "userAgent": "COOLWSD HTTP Agent 23.05.5.4",
    "version": "28.0.0.11",
    "data": {
        "app": "files_versions"
    }
}

@SystemKeeper
Copy link
Contributor

Edit web:
Bildschirmfoto 2023-12-14 um 21 34 08

Edit iOS:
Bildschirmfoto 2023-12-14 um 21 32 14

@jakobroehrl
Copy link

I experience this every time a office doc was edited by a mobile app.
The mobile call is different to the browser call: #40090 (comment)
But I do not understand why it does not occur on my AIO installation. Same nc version, same versions app version (version app is enabled)

@kyrofa
Copy link
Member

kyrofa commented Dec 18, 2023

I tried to take a look if the problem comes from richdocuments

FYI, I have this issue, and don't have richdocuments.

@jakobroehrl
Copy link

Retested on 28.0.1.0 with richdocuments 8.3.0, same error

same on my site

@githubkoma
Copy link

githubkoma commented Jan 14, 2024

Ah, forgot to add ->getUID() at the end 🙈. Sorry, can you try again with this patch?

null_path_files_versions_hook.txt

applying this patch while debugging this error also happening within multiboards app the following log comes up:

{"reqId":"aF19X6Z9SeoNw7KRMfLe","level":3,"time":"2024-01-14T14:03:24+00:00","remoteAddr":"127.0.0.1","user":"user2","app":"files_versions","method":"PUT","url":"/index.php/apps/multiboards/file/save?fileId=null&shareToken=tN9LqDcZ5qcYScD","message":"Failed to find relative path for file for /admin/files/MultiBoard 14 Jan 2024 101608 GMT.mboard and owner admin","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0","version":"28.0.1.1","data":{"app":"files_versions"}}

thing is it does not happen if the logged in user is the same user who created and shared the file of relevance,
it only happens if another NC user is logged in, tries to access the file via sharetoken, and then this error throws..

@blizzz
Copy link
Member

blizzz commented Jan 15, 2024

I tried to take a look if the problem comes from richdocuments

FYI, I have this issue, and don't have richdocuments.

@kyrofa Would you mind sharing your stack trace, too?

@kyrofa
Copy link
Member

kyrofa commented Jan 15, 2024

Hey @blizzz, already did a ways up.

@blizzz
Copy link
Member

blizzz commented Jan 15, 2024

Hey @blizzz, already did a ways up.

Uh, sorry, missed that! Thanks!

@artonge
Copy link
Contributor

artonge commented Jan 17, 2024

Hey, could one of you test the following PR: #42891 ?

@SystemKeeper
Copy link
Contributor

Hey, could one of you test the following PR: #42891 ?

Hey, couldn't test it too much, but a quick test showed no exception and a version being created! Thanks!

@githubkoma
Copy link

githubkoma commented Jan 17, 2024

Hey, could one of you test the following PR: #42891 ?

for me and a quick test it looks like this:

  • [x] fixes the issue
  • [dont know] side effects

@jakobroehrl
Copy link

Fixed for me with the latest NC version, I actived the version App again.

@defekT1312
Copy link

Hey, just want to tell you that I'm having the same Problem, disabling Versions solves the Problem it seems.

I'm on:
Versions 1.21.0
NextCloudPi 28.0.3
Backup 1.4.0

No Richdocuments or Office installed.

Please tell me if I can do anything to help you figuring this out.

@artonge
Copy link
Contributor

artonge commented Mar 13, 2024

Please tell me if I can do anything to help you figuring this out.

What could help would be to add the following lines in apps/files_versions/lib/Listener/FileEventsListener.php, right before the last return null;.

$this->logger->error('Failed to find relative path for file for ' . $node->getPath() . ' and owner ' . $node->getOwner()->getUID());

And then to trigger the error again, and to post the generated logs here.

@defekT1312
Copy link

Please tell me if I can do anything to help you figuring this out.

What could help would be to add the following lines in apps/files_versions/lib/Listener/FileEventsListener.php, right before the last return null;.

$this->logger->error('Failed to find relative path for file for ' . $node->getPath() . ' and owner ' . $node->getOwner()->getUID());

And then to trigger the error again, and to post the generated logs here.

I'm sorry, I gave up on the backup app. I was trying for 2 days and I'm tired of this app. Using Borg now, works like a charm.

@ClundXIII
Copy link

ClundXIII commented Apr 28, 2024

And then to trigger the error again, and to post the generated logs here.

We have the same issue, latest version of Collabora (coolwsd 24.04.1.4) and Nextcloud v28.0.5:

Failed to find relative path for file for /<user name 1>/files/<group folder>/<file path inside group folder>.docx and owner <user name 2>

user name 1: the user who I presume created the document
user name 2: myself when I try to edit the file

@SystemKeeper
Copy link
Contributor

I am also seeing the exception again. Here is the log as requested:

{
    "reqId": "dzYhDuN388vLllOuTTuc",
    "level": 3,
    "time": "2024-05-05T15:19:33+02:00",
    "remoteAddr": "172.30.150.2",
    "user": "test",
    "app": "files_versions",
    "method": "POST",
    "url": "/index.php/apps/richdocuments/wopi/files/..../contents?access_token=....&access_token_ttl=0",
    "message": "Failed to find relative path for file for /marcel.mueller/files/<Folder>/<Subfolder>/2024.xlsx and owner test",
    "userAgent": "COOLWSD HTTP Agent 24.04.1.4",
    "version": "29.0.0.19",
    "data": {
        "app": "files_versions"
    }
}

Notes:

  • <Folder> is a groupfolder
  • User marcel.mueller shared the folder <Subfolder> with user test
  • User test tries to edit the file via the iOS files app

When I add an additional log to the beginning of the getPathForNode function and try the same via the Web (so not iOS), like this:

$this->logger->error('Trying to find relative path for file for ' . $node->getPath() . ' and owner ' . $node->getOwner()->getUID());

I get:

Trying to find relative path for file for /test/files/<Subfolder>/2024.xlsx and owner marcel.mueller

and a version is created (so user and owner are swapped).

What works for me is to still try to get the owner based on the path:

diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php
index 3273f1f9c40..b3254b0e424 100644
--- a/apps/files_versions/lib/Listener/FileEventsListener.php
+++ b/apps/files_versions/lib/Listener/FileEventsListener.php
@@ -403,6 +403,22 @@ class FileEventsListener implements IEventListener {
                        }
                }
 
+               // Try to get the owner of the file based on the path as a fallback
+               $parts = explode('/', $node->getPath(), 4);
+               if (count($parts) === 4) {
+                       $owner = $parts[1];
+
+                       $path = $this->rootFolder
+                               ->getUserFolder($owner)
+                               ->getRelativePath($node->getPath());
+
+                       if ($path !== null) {
+                               return $path;
+                       }
+               }
+

What I still don't get, why is the user/owner swapped when editing the file on the iOS app in the first place?

@SystemKeeper SystemKeeper reopened this May 5, 2024
@SystemKeeper
Copy link
Contributor

What I still don't get, why is the user/owner swapped when editing the file on the iOS app in the first place?

Judging from #44294 (comment) that seems expected.

Also nextcloud/richdocuments#3558 recently changed the user when editing, which could also make a difference here I guess.

@juliushaertl Maybe there’s a better way to get the path in this scenario with Collabora ?

@juliushaertl
Copy link
Member

juliushaertl commented May 8, 2024

I worked on a better approach for storages that do not have a dedicated owner with #44294 nextcloud/groupfolders#2872 That way we would no longer need to get the path but could just use the storage provided user id

@SystemKeeper
Copy link
Contributor

@juliushaertl I upgraded to 30 RC, both PRs are included, still I am unable to edit shared richdocuments files. The only way to make it work is to apply the patch I posted at #40090 (comment).

Is there still something missing or should it work?

Here's the log:

{
  "Exception": "Exception",
  "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1103",
  "Code": 0,
  "Trace": [
    {
      "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
      "line": 161,
      "function": "dispatch",
      "class": "OC\\AppFramework\\Http\\Dispatcher",
      "type": "->"
    },
    {
      "file": "/var/www/nextcloud/lib/private/Route/Router.php",
      "line": 309,
      "function": "main",
      "class": "OC\\AppFramework\\App",
      "type": "::"
    },
    {
      "file": "/var/www/nextcloud/lib/base.php",
      "line": 996,
      "function": "match",
      "class": "OC\\Route\\Router",
      "type": "->"
    },
    {
      "file": "/var/www/nextcloud/index.php",
      "line": 24,
      "function": "handleRequest",
      "class": "OC",
      "type": "::"
    }
  ],
  "File": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
  "Line": 146,
  "Previous": {
    "Exception": "TypeError",
    "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/nextcloud/lib/private/Files/View.php",
        "line": 492,
        "function": "basicOperation",
        "class": "OC\\Files\\View",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/Filesystem.php",
        "line": 516,
        "function": "file_exists",
        "class": "OC\\Files\\View",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/apps/files_versions/lib/Storage.php",
        "line": 158,
        "function": "file_exists",
        "class": "OC\\Files\\Filesystem",
        "type": "::"
      },
      {
        "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
        "line": 174,
        "function": "store",
        "class": "OCA\\Files_Versions\\Storage",
        "type": "::"
      },
      {
        "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
        "line": 80,
        "function": "write_hook",
        "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/EventDispatcher/ServiceEventListener.php",
        "line": 68,
        "function": "handle",
        "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
        "line": 230,
        "function": "__invoke",
        "class": "OC\\EventDispatcher\\ServiceEventListener",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
        "line": 59,
        "function": "callListeners",
        "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
        "line": 67,
        "function": "dispatch",
        "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
        "line": 79,
        "function": "dispatch",
        "class": "OC\\EventDispatcher\\EventDispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/Node/HookConnector.php",
        "line": 74,
        "function": "dispatchTyped",
        "class": "OC\\EventDispatcher\\EventDispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/legacy/OC_Hook.php",
        "line": 82,
        "function": "write",
        "class": "OC\\Files\\Node\\HookConnector",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/View.php",
        "line": 560,
        "function": "emit",
        "class": "OC_Hook",
        "type": "::"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/View.php",
        "line": 603,
        "function": "emit_file_hooks_pre",
        "class": "OC\\Files\\View",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/Node/File.php",
        "line": 52,
        "function": "file_put_contents",
        "class": "OC\\Files\\View",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
        "line": 467,
        "function": "putContent",
        "class": "OC\\Files\\Node\\File",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
        "line": 756,
        "function": "OCA\\Richdocuments\\Controller\\{closure}",
        "class": "OCA\\Richdocuments\\Controller\\WopiController",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
        "line": 733,
        "function": "retryOperation",
        "class": "OCA\\Richdocuments\\Controller\\WopiController",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/Lock/LockManager.php",
        "line": 68,
        "function": "OCA\\Richdocuments\\Controller\\{closure}",
        "class": "OCA\\Richdocuments\\Controller\\WopiController",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
        "line": 736,
        "function": "runInScope",
        "class": "OC\\Files\\Lock\\LockManager",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
        "line": 466,
        "function": "wrappedFilesystemOperation",
        "class": "OCA\\Richdocuments\\Controller\\WopiController",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 208,
        "function": "putFile",
        "class": "OCA\\Richdocuments\\Controller\\WopiController",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 114,
        "function": "executeController",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
        "line": 161,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Route/Router.php",
        "line": 309,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::"
      },
      {
        "file": "/var/www/nextcloud/lib/base.php",
        "line": 996,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/index.php",
        "line": 24,
        "function": "handleRequest",
        "class": "OC",
        "type": "::"
      }
    ],
    "File": "/var/www/nextcloud/lib/private/Files/View.php",
    "Line": 1103
  },
  "message": "Uncaught error: OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1103",
  "exception": {},
  "CustomMessage": "Uncaught error: OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1103"
}

@juliushaertl
Copy link
Member

Indeed, i could reproduce that, could you check the patch in nextcloud/richdocuments#3948 and see if that does the trick for you?

@SystemKeeper
Copy link
Contributor

and see if that does the trick for you?

Works fine and resolves this issue for me!

@PaulosV
Copy link

PaulosV commented Aug 27, 2024

On Nextcloud 30.0.0RC2, with the PRs applied, I am still getting the error. I am however using group folders, and the file I am trying to open is through a public link. I have R/W access to that file, and it works fine when accessing it through the group folder directly, and it is also okay to open in a private browser (not logged in).

The only workaround that still works reliably in my scenario is this: #40090 (comment)

Should I open a new bug for this, maybe?

@juliushaertl
Copy link
Member

Please read the last 2 messages, there is a fix coming with the next richdocuments release

@PaulosV
Copy link

PaulosV commented Aug 28, 2024

My bad for not mentioning, but I have applied the patch from nextcloud/richdocuments#3948 and it did not resolve the issue for me. (edit: I have also manually checked all the other files mentioned in this bug, and they already have the modifications from the patches. With the added logging from #40090 (comment), I can see the same pattern as this person. Maybe I am missing something, but I cannot see it at the moment.)

@PaulosV
Copy link

PaulosV commented Sep 21, 2024

After updating to Nextcloud 30.0.0, and richdocuments to v8.5.0, I still experience the issue.

What we are using, and I feel is relevant (feel free to request more)

Failed to find relative path for file for /<sharing user>/files/SIN admins/Nova AP/KdoKdyMuze.xlsx and owner <my username> 

Log below.

{
    "reqId": "Zp645B8Y96zQNWRCNYn2",
    "level": 3,
    "time": "2024-09-21T10:21:40+00:00",
    "remoteAddr": "2001:718:2:880::110:40",
    "user": "--",
    "app": "richdocuments",
    "method": "POST",
    "url": "/index.php/apps/richdocuments/wopi/files/2271184_oc8lvg07l31z/contents?access_token=<secret>&access_token_ttl=0",
    "message": "Uncaught error: OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1103",
    "userAgent": "COOLWSD HTTP Agent 24.04.6.1",
    "version": "30.0.0.14",
    "exception": {
        "Exception": "Exception",
        "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1103",
        "Code": 0,
        "Trace": [
            {
                "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
                "line": 161,
                "function": "dispatch",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Route/Router.php",
                "line": 302,
                "function": "main",
                "class": "OC\\AppFramework\\App",
                "type": "::"
            },
            {
                "file": "/var/www/nextcloud/lib/base.php",
                "line": 1001,
                "function": "match",
                "class": "OC\\Route\\Router",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/index.php",
                "line": 24,
                "function": "handleRequest",
                "class": "OC",
                "type": "::"
            }
        ],
        "File": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
        "Line": 146,
        "Previous": {
            "Exception": "TypeError",
            "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492",
            "Code": 0,
            "Trace": [
                {
                    "file": "/var/www/nextcloud/lib/private/Files/View.php",
                    "line": 492,
                    "function": "basicOperation",
                    "class": "OC\\Files\\View",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Filesystem.php",
                    "line": 516,
                    "function": "file_exists",
                    "class": "OC\\Files\\View",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/apps/files_versions/lib/Storage.php",
                    "line": 158,
                    "function": "file_exists",
                    "class": "OC\\Files\\Filesystem",
                    "type": "::"
                },
                {
                    "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
                    "line": 174,
                    "function": "store",
                    "class": "OCA\\Files_Versions\\Storage",
                    "type": "::"
                },
                {
                    "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
                    "line": 80,
                    "function": "write_hook",
                    "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/EventDispatcher/ServiceEventListener.php",
                    "line": 68,
                    "function": "handle",
                    "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                    "line": 230,
                    "function": "__invoke",
                    "class": "OC\\EventDispatcher\\ServiceEventListener",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                    "line": 59,
                    "function": "callListeners",
                    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
                    "line": 67,
                    "function": "dispatch",
                    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
                    "line": 79,
                    "function": "dispatch",
                    "class": "OC\\EventDispatcher\\EventDispatcher",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Node/HookConnector.php",
                    "line": 74,
                    "function": "dispatchTyped",
                    "class": "OC\\EventDispatcher\\EventDispatcher",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/legacy/OC_Hook.php",
                    "line": 82,
                    "function": "write",
                    "class": "OC\\Files\\Node\\HookConnector",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/View.php",
                    "line": 560,
                    "function": "emit",
                    "class": "OC_Hook",
                    "type": "::"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/View.php",
                    "line": 603,
                    "function": "emit_file_hooks_pre",
                    "class": "OC\\Files\\View",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Node/File.php",
                    "line": 52,
                    "function": "file_put_contents",
                    "class": "OC\\Files\\View",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 467,
                    "function": "putContent",
                    "class": "OC\\Files\\Node\\File",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 756,
                    "function": "OCA\\Richdocuments\\Controller\\{closure}",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args": [
                        "*** sensitive parameters replaced ***"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 733,
                    "function": "retryOperation",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Lock/LockManager.php",
                    "line": 58,
                    "function": "OCA\\Richdocuments\\Controller\\{closure}",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args": [
                        "*** sensitive parameters replaced ***"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 736,
                    "function": "runInScope",
                    "class": "OC\\Files\\Lock\\LockManager",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 466,
                    "function": "wrappedFilesystemOperation",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 208,
                    "function": "putFile",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 114,
                    "function": "executeController",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
                    "line": 161,
                    "function": "dispatch",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Route/Router.php",
                    "line": 302,
                    "function": "main",
                    "class": "OC\\AppFramework\\App",
                    "type": "::"
                },
                {
                    "file": "/var/www/nextcloud/lib/base.php",
                    "line": 1001,
                    "function": "match",
                    "class": "OC\\Route\\Router",
                    "type": "->"
                },
                {
                    "file": "/var/www/nextcloud/index.php",
                    "line": 24,
                    "function": "handleRequest",
                    "class": "OC",
                    "type": "::"
                }
            ],
            "File": "/var/www/nextcloud/lib/private/Files/View.php",
            "Line": 1103
        },
        "message": "Uncaught error: OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1103",
        "exception": [],
        "CustomMessage": "Uncaught error: OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1103"
    },
    "id": "66eea08ba7ee2"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 27-feedback bug feature: filesystem feature: versions
Projects
None yet
Development

Successfully merging a pull request may close this issue.