[Solved] Error creating the share: Node for share not found

Nextcloud version (eg, 20.0.5): 23.0.10.1
Operating system and version (eg, Ubuntu 20.04): Debian Buster
Apache or nginx version (eg, Apache 2.4.25): nginx/1.14.2
PHP version (eg, 7.4): PHP7.4-fpm

The issue you are facing:
Unable to share a folder that is in a groupfolder.

Error creating the share: Node for share not found, fileid: 66665676

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Shared folder with other users.
  2. User who shared the folder had permissions to that folder removed. Share nolonger appearing in the shares list.
  3. Resharing the folder by a user that does have permission resulted in the error in the gui;

Error creating the share: Node for share not found, fileid: 66665676

The output of your Nextcloud log in Admin > Logging:

Formatted;
[no app in context] Error: Node for share not found, fileid: 66665676
POST /ocs/v2.php/apps/files_sharing/api/v1/shares
from xx.xx.xx.xx by xx@emailaddress.com at 2022-10-11T19:52:20+01:00

Raw;

{"reqId":"hP40weiYjuIwGDyggLDy","level":3,"time":"2022-10-11T14:06:25+01:00","remoteAddr":"xx.xx.xx.xx","user":"user@emailaddress.com","app":"no app in context","method":"POST","url":"/ocs/v2.php/apps/files_sharing/api/v1/shares","message":"Node for share not found, fileid: 66665676","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0","version":"23.0.9.1","exception":{"Exception":"OCP\\Files\\NotFoundException","Message":"Node for share not found, fileid: 66665676","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/private/Share20/LegacyHooks.php","line":161,"function":"getNode","class":"OC\\Share20\\Share","type":"->"},{"file":"/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php","line":264,"function":"postShare","class":"OC\\Share20\\LegacyHooks","type":"->"},{"file":"/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php","line":239,"function":"doDispatch","class":"Symfony\\Component\\EventDispatcher\\EventDispatcher","type":"->"},{"file":"/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php","line":73,"function":"callListeners","class":"Symfony\\Component\\EventDispatcher\\EventDispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/EventDispatcher/SymfonyAdapter.php","line":123,"function":"dispatch","class":"Symfony\\Component\\EventDispatcher\\EventDispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/Share20/Manager.php","line":835,"function":"dispatch","class":"OC\\EventDispatcher\\SymfonyAdapter","type":"->"},{"file":"/var/www/nextcloud/apps/files_sharing/lib/Controller/ShareAPIController.php","line":672,"function":"createShare","class":"OC\\Share20\\Manager","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":217,"function":"createShare","class":"OCA\\Files_Sharing\\Controller\\ShareAPIController","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":126,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":157,"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/ocs/v1.php","line":62,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/nextcloud/ocs/v2.php","line":23,"args":["/var/www/nextcloud/ocs/v1.php"],"function":"require_once"}],"File":"/var/www/nextcloud/lib/private/Share20/Share.php","Line":190,"CustomMessage":"--"},"id":"63456a9e10800"}

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'debug' => false,
  'loglevel' => 1,
  'instanceid' => 'xx',
  'passwordsalt' => 'xx',
  'secret' => 'xx',
  'default_phone_region' => 'GB',
  'allow_local_remote_servers' => true,
  'trusted_domains' =>
  array (
    0 => 'xx',
    1 => 'xx',
    2 => 'xx',
  ),
  'datadirectory' => '/media/storage/nc_data',
  'dbtype' => 'mysql',
  'version' => '23.0.10.1',
  'overwrite.cli.url' => 'https://xx',
  'dbname' => 'xx',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'xx',
  'dbpassword' => 'xx',
  'installed' => true,
  'activity_expire_days' => 14,
  'auth.bruteforce.protection.enabled' => true,
  'blacklisted_files' =>
  array (
    0 => '.htaccess',
    1 => 'Thumbs.db',
    2 => 'thumbs.db',
  ),
  'cron_log' => true,
  'enable_previews' => true,
  'preview_max_x' => '1080',
  'preview_max_y' => '1920',
  'preview_libreoffice_path' => '/usr/bin/libreoffice',
  'enabledPreviewProviders' =>
  array (
    0 => 'OC\\Preview\\PNG',
    1 => 'OC\\Preview\\JPEG',
    2 => 'OC\\Preview\\GIF',
    3 => 'OC\\Preview\\BMP',
    4 => 'OC\\Preview\\XBitmap',
    5 => 'OC\\Preview\\Movie',
    6 => 'OC\\Preview\\PDF',
    7 => 'OC\\Preview\\MP3',
    8 => 'OC\\Preview\\TXT',
    9 => 'OC\\Preview\\MarkDown',
  ),
  'filesystem_check_changes' => 0,
  'filelocking.enabled' => 'true',
  'htaccess.RewriteBase' => '/',
  'integrity.check.disabled' => false,
  'knowledgebaseenabled' => false,
  'logfile' => '/var/log/nextcloud/nextcloud.log',
  'logtimezone' => 'Europe/London',
  'log_rotate_size' => 104857600,
  'maintenance' => false,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'overwriteprotocol' => 'https',
  'preview_max_scale_factor' => 1,
  'redis' =>
  array (
    'host' => '/var/run/redis/redis-server.sock',
    'port' => 0,
    'timeout' => 0.0,
  ),
  'quota_include_external_storage' => false,
  'share_folder' => '/Shares',
  'defaultapp' => 'files',
  'skeletondirectory' => '',
  'theme' => '',
  'trashbin_retention_obligation' => 'auto, 7',
  'updater.release.channel' => 'stable',
  'default_locale' => 'en_GB',
  'app.mail.transport' => 'php-mail',
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'ssl',
  'mail_sendmailmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_from_address' => 'xx',
  'mail_domain' => 'xx',
  'mail_smtphost' => 'xx',
  'mail_smtpport' => '465',
  'mail_smtpname' => 'xx',
  'mail_smtppassword' => 'xx',
  'app_install_overwrite' =>
  array (
    0 => 'files_external_ipfs',
    1 => 'mindmap_app',
  ),
  'lost_password_link' => 'disabled',
  'jpeg_quality' => '60',
  'trusted_proxies' =>
  array (
    0 => '127.0.0.1',
    1 => '::1',
    2 => 'xx',
    3 => 'xx',
  ),
  'updater.secret' => 'xx'
);

Just posting here how to fix this if I encounter this again or for other unfortunates…
Log in to MySQL/MariaDB whatever and ‘use’ your nextcloud database;

MariaDB [(none)]> use nextcloud;
Database changed

find the offending share, using the file source reference (fileid:) from the original error to confirm that this is the share that’s giving you a headache…

MariaDB [nextcloud]> SELECT * FROM `oc_share` WHERE `file_source` = 66665676;

and then remove the share;

MariaDB [nextcloud]> DELETE FROM `oc_share` WHERE `file_source` = 66665676;
Query OK, 38 rows affected (0.286 sec)

You should now be able to reshare that folder.