Problem/Motivation

When someone adds a folder for config split, but the folder is not part of the repository or it's not yet created the configuration export fails with the following exception:

The .yml files in your export directory (../config/default) will be deleted and replaced with the active config. (y/n): y
InvalidArgumentException: The split storage has to be set and exist for write operations. in docroot/modules/contrib/config_split/src/Plugin/ConfigFilter/SplitFilter.php:166           [error]
Stack trace:
#0 docroot/modules/contrib/config_filter/src/Config/FilteredStorage.php(93): Drupal\config_split\Plugin\ConfigFilter\SplitFilter->filterWrite('block.block.adm...', Array)
#1 vendor/drush/drush/commands/core/config.drush.inc(518): Drupal\config_filter\Config\FilteredStorage->write('block.block.adm...', Array)
#2 vendor/drush/drush/commands/core/config.drush.inc(456): _drush_config_export('sync', '...', false)
#3 vendor/drush/drush/includes/command.inc(422): drush_config_export()
#4 vendor/drush/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
#5 vendor/drush/drush/includes/command.inc(199): drush_command()
#6 vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#7 vendor/drush/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#8 vendor/drush/drush/drush.php(12): drush_main()
#9 {main}

The end result however is that all configuration yml files are already deleted, so this error is causing inconvenience.

If you are not using version control system with the configuration management, this exception will cause data-loss.

Proposed resolution

Attempt to create the split folder when writing to it before failing.

Remaining tasks

Discussion.

User interface changes

TBD.

API changes

TBD, none expected.

Data model changes

TBD, none expected.

Comments

ndobromirov created an issue. See original summary.

bircher’s picture

Hello

Unfortunately the filter can not know what operation is being performed, it correctly fails when trying to write to a folder that does not exist.
We added a warning to the UI about this in #2906189: verify config directory exists in form validation.
We could try to create the folder if it doesn't exist before writing to it, but I am not sure that this is actually better or would create problems in other workflows. As such that would be a feature request.

There is no data loss even if you do not use git to track your configuration. All you have to do is create the folder and export the configuration again. The configuration export operation merely duplicates the data to the disk which exists also in the database.

bircher’s picture

Title: Configuration files lost due to an error. » Create split folder automatically when it is needed.
Category: Bug report » Feature request
Issue summary: View changes
irinaz’s picture

Hi, I am using UI for config_split module /admin/config/development/configuration/config-split on a site that is built on Pantheon hosting. Currently I do not have git access to this site. I add new split configuration here /admin/config/development/configuration/config-split/test_config/edit and enter path for directory "../config/my-split-folder", and when I save I (correctly) get warning "The storage path "../config/my-split-folder" for test config Configuration Split Setting does not exist. Make sure it exists and is writable."

Is there a way to create this folder via UI? Do you need to get access to code and add empty folder in the root directory? What are best practices for this new module?
Thank you, Irina

aiphes’s picture

I get this same error , while I change permissions on folders to 777:

 ls -l /var/www/drupal-8/sites/d8dev-mg/config_d8mg/
drwxrwxrwx 4 webmaster www-data 4096 mai   22 14:17 environnement
drwxrwxrwx 2 webmaster www-data 4096 mai   22 14:17 sync
webmaster@ubuntuserver18:~$ ls -l /var/www/drupal-8/sites/d8dev-mg/config_d8mg/environnement/
total 8
drwxrwxrwx 2 webmaster www-data 4096 mai   29 10:30 dev
drwxrwxrwx 2 webmaster www-data 4096 mai   22 14:17 prod

I don't understand why this happen. If someone has an idea to fix it ?
Thanks

aiphes’s picture

Still there on D8.8.2

In SplitFilter.php line 166:
  The split storage has to be set and exist for write operations.
bennlich’s picture

Maybe a compromise would be to print out the missing path in the error so that it's easy for the user to know what to create?

  • bircher committed 51b50c2 on 8.x-1.x
    Issue #2926477 by bircher: Create split folder automatically when it is...
bircher’s picture

Status: Active » Fixed

I changed my mind...
There may still be some negative consequences, but we can always revert this if it turns out to out-weight the convenience.

  • bircher committed 51b50c2 on 2.0.x
    Issue #2926477 by bircher: Create split folder automatically when it is...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.