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

Can media library pro validation catch more exceptions in the validation? #3770

Open
davidyell opened this issue Jan 22, 2025 · 0 comments
Open

Comments

@davidyell
Copy link

Discussed in #3720

Originally posted by davidyell October 29, 2024
I am interested to understand if there is a way to have the media library catch more exceptions as validation failures.

We have an occasional bug where we get League\Flysystem\UnableToRetrieveMetadata which comes from the src/Livewire/LivewireUploaderComponent.php class and it's getUploadError() method. This is when media-library tries to validate against a file which does not exist.

The stacktrace seems to indicate that the exception originates from the getUploadError() method.

    protected function getUploadError(): ?string
    {
        $uploadError = null;

        $field = $this->multiple ? 'upload.*' : 'upload';

        try {
            $this->validate([
                $field => $this->rules,
            ], ["{$field}.mimes" => __('media-library::validation.type')]);
        } catch (ValidationException $validationException) {
            $uploadError = Arr::flatten($validationException->errors())[0];

            if ($this->add) {
                $this->dispatch("{$this->name}:showListErrorMessage", $uploadError);
            }
        }

        return $uploadError;
    }

As you can see, it happily catches any ValidationException but does not handle any exceptions thrown from the Flysystem package, such as the UnableToRetrieveMetadata exception.

Is there a neat way to have any exceptions thrown by Flysystem be caught here and instead this method can throw a ValidationException?

@davidyell davidyell changed the title Can media library validation catch more exceptions in the validation? Can media library pro validation catch more exceptions in the validation? Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant