@PiotrIr all user permission is ok on your data directory and nextcloud directory ?
if not :
sudo chown -R www-data:www-data /path-directory-of-nextcloud
sudo chmod -R 750 /path-directory-of-nextcloud
sudo chown -R www-data:www-data /path-directory-of-data-user
sudo chmod -R 750 /path-directory-of-data-user
if you have the same error again maybe make a backup of your config.php, data user and your database. Try to reinstall nextcloud and restore your data
backup : Backup — Nextcloud latest Administration Manual latest documentation
restore backup : Restoring backup — Nextcloud latest Administration Manual latest documentation
( don’t forget to set the correct directory permissions after downloading nextcloud and transferring your data)