verbb / icon-picker

A Craft CMS field to select SVG or font icons from a folder for use in your content.
Other
17 stars 8 forks source link

"ValueError: Path cannot be empty" after upgrade #68

Closed corneliusio closed 1 year ago

corneliusio commented 1 year ago

Describe the bug

Upgrading from 2.0.0-beta.5 to 2.0.10 with multiple SVG folder sets. All sets were correctly migrated/created on update however when editing a page with the configured icon field we get a "ValueError: Path cannot be empty after upgrade" preventing the page from being editable. I believe it's possibly due to the values saved in the DB for these fields have stored the original path to the SVG files. The original structure for our icons was:

web/icons/fontawesome/[brands|regular|solid|light|duotone]/*.svg
web/icons/mostly-serious/team/*.svg
web/icons/mostly-serious/*.svg

Because Icon Picker used to detect icons in subdirectors this worked fine for us. Knowing this wouldn't work I moved all of the icons over to the following structure:

web/icon-picker/fontawesome-brands/*.svg
web/icon-picker/fontawesome-duotone/*.svg
web/icon-picker/fontawesome-light/*.svg
web/icon-picker/fontawesome-regular/*.svg
web/icon-picker/fontawesome-solid/*.svg
web/icon-picker/mostly-serious-brand/*.svg
web/icon-picker/mostly-serious-team/*.svg

As mentioned above, these directories do appear to have been converted to icon sets correctly. However, when in Twig for the front-end of the site I can echo out the content of the field directly ({{ element.icon }}) which will output the old URL to the file location. However when attempting to get more info by JSON encoding the object ({{ element.icon|json_encode(128) }}) I also get the ValueError on the front-end as well.

Here is the full stack trace if it's at all helpful.

ValueError: Path cannot be empty in /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/verbb/icon-picker/src/models/Icon.php:209
Stack trace:
#0 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/verbb/icon-picker/src/models/Icon.php(209): file_get_contents('')
#1 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/verbb/icon-picker/src/models/Icon.php(168): verbb\iconpicker\models\Icon->getInline()
#2 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/verbb/icon-picker/src/models/Icon.php(102): verbb\iconpicker\models\Icon->getDisplayValue()
#3 [internal function]: verbb\iconpicker\models\Icon->jsonSerialize()
#4 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/web/twig/Extension.php(639): json_encode(Object(verbb\iconpicker\models\Icon), 11, 512)
#5 /Users/cornelius/Git/@mostlyserious/mostlyserious/storage/runtime/compiled_templates/c8/c8d91649727a63c3a4bfb37241d021a9.php(41): craft\web\twig\Extension->jsonEncodeFilter(Object(verbb\iconpicker\models\Icon))
#6 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/twig/twig/src/Template.php(394): __TwigTemplate_7b23e72bc4691f8a0b8d223d8126b69d->doDisplay(Array, Array)
#7 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#8 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#9 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/twig/twig/src/TemplateWrapper.php(40): Twig\Template->render(Array, Array)
#10 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/twig/twig/src/Environment.php(277): Twig\TemplateWrapper->render(Array)
#11 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/web/View.php(451): Twig\Environment->render('icon-picker/_fi...', Array)
#12 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/verbb/icon-picker/src/fields/IconPickerField.php(101): craft\web\View->renderTemplate('icon-picker/_fi...', Array)
#13 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(269): verbb\iconpicker\fields\IconPickerField->getInputHtml(Object(verbb\iconpicker\models\Icon), Object(craft\elements\MatrixBlock))
#14 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/fieldlayoutelements/BaseField.php(215): craft\fieldlayoutelements\CustomField->inputHtml(Object(craft\elements\MatrixBlock), false)
#15 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(214): craft\fieldlayoutelements\BaseField->formHtml(Object(craft\elements\MatrixBlock), false)
#16 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/web/View.php(1611): craft\fieldlayoutelements\CustomField->craft\fieldlayoutelements\{closure}()
#17 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(215): craft\web\View->namespaceInputs(Object(Closure), 'fields')
#18 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/models/FieldLayout.php(738): craft\fieldlayoutelements\CustomField->formHtml(Object(craft\elements\MatrixBlock), false)
#19 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/web/View.php(1605): craft\models\FieldLayout->craft\models\{closure}()
#20 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/models/FieldLayout.php(737): craft\web\View->namespaceInputs(Object(Closure), NULL)
#21 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/twig/twig/src/Extension/CoreExtension.php(1607): craft\models\FieldLayout->createForm(Object(craft\elements\MatrixBlock), false)
#22 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/helpers/Template.php(110): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\models\FieldLayout), 'createForm', Array, 'method', false, false)
#23 /Users/cornelius/Git/@mostlyserious/mostlyserious/storage/runtime/compiled_templates/e7/e70fb6ec0048c4fe9f011a563deb15fd.php(293): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\models\FieldLayout), 'createForm', Array, 'method')
#24 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/twig/twig/src/Template.php(394): __TwigTemplate_5bd32f4ee857ca1d90c00ab53e500be8->doDisplay(Array, Array)
#25 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#26 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#27 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/twig/twig/src/TemplateWrapper.php(40): Twig\Template->render(Array, Array)
#28 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/twig/twig/src/Environment.php(277): Twig\TemplateWrapper->render(Array)
#29 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/web/View.php(451): Twig\Environment->render('_components/fie...', Array)
#30 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/fields/Matrix.php(747): craft\web\View->renderTemplate('_components/fie...', Array)
#31 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/base/Field.php(471): craft\fields\Matrix->inputHtml(Array, Object(craft\elements\GlobalSet))
#32 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(269): craft\base\Field->getInputHtml(Object(craft\elements\db\MatrixBlockQuery), Object(craft\elements\GlobalSet))
#33 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/fieldlayoutelements/BaseField.php(215): craft\fieldlayoutelements\CustomField->inputHtml(Object(craft\elements\GlobalSet), false)
#34 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(214): craft\fieldlayoutelements\BaseField->formHtml(Object(craft\elements\GlobalSet), false)
#35 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/web/View.php(1611): craft\fieldlayoutelements\CustomField->craft\fieldlayoutelements\{closure}()
#36 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/fieldlayoutelements/CustomField.php(215): craft\web\View->namespaceInputs(Object(Closure), 'fields')
#37 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/models/FieldLayout.php(738): craft\fieldlayoutelements\CustomField->formHtml(Object(craft\elements\GlobalSet), false)
#38 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/web/View.php(1605): craft\models\FieldLayout->craft\models\{closure}()
#39 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/models/FieldLayout.php(737): craft\web\View->namespaceInputs(Object(Closure), NULL)
#40 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/controllers/GlobalsController.php(173): craft\models\FieldLayout->createForm(Object(craft\elements\GlobalSet), false, Array)
#41 [internal function]: craft\controllers\GlobalsController->actionEditContent('footer', Object(craft\elements\GlobalSet))
#42 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#43 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#44 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('edit-content', Array)
#45 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/web/Application.php(301): yii\base\Module->runAction('globals/edit-co...', Array)
#46 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('globals/edit-co...', Array)
#47 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/craftcms/cms/src/web/Application.php(286): yii\web\Application->handleRequest(Object(craft\web\Request))
#48 /Users/cornelius/Git/@mostlyserious/mostlyserious/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#49 /Users/cornelius/Git/@mostlyserious/mostlyserious/web/index.php(12): yii\base\Application->run()
#50 /Users/cornelius/.composer/vendor/laravel/valet/server.php(234): require('/Users/corneliu...')
#51 {main}

Steps to reproduce

I believe the above description should provide enough details for reproduction.

Craft CMS version

4.3.5

Plugin version

2.0.10

Multi-site?

No

Additional context

No response

engram-design commented 1 year ago

So the error being thrown should be fixed for the next release, but it's throwing it because it cannot return the inline value of your SVG, so it can't find it on the file system.

But this is a great point, I completely forgot that we used to handle subfolders. Did you update your folder structure before the v2 migration, or after?

Regardless, these should also work now (and shouldn't need to be migrated), as they will still use the same path info. You may just need to clear your icon caches.

See 2.0.11

corneliusio commented 1 year ago

Fantastic! Thanks for the quick turnaround and it's good to know we can use those subdirectories again if we want. Appreciate y'alls work on all these plugins.

I created the new directory structure before the migration since I knew if I didn't I'd have to create the icon sets manually.