diff --git a/packages/@uppy/core/src/Uppy.js b/packages/@uppy/core/src/Uppy.js index fb61521376..cf38723b3e 100644 --- a/packages/@uppy/core/src/Uppy.js +++ b/packages/@uppy/core/src/Uppy.js @@ -390,14 +390,12 @@ class Uppy { } validateRestrictions (file, files = this.getFiles()) { - // TODO: directly return the Restriction error in next major version. - // we create RestrictionError's just to discard immediately, which doesn't make sense. try { this.#restricter.validate(file, files) - return { result: true } } catch (err) { - return { result: false, reason: err.message } + return err } + return null } #checkRequiredMetaFieldsOnFile (file) { diff --git a/packages/@uppy/core/src/Uppy.test.js b/packages/@uppy/core/src/Uppy.test.js index 31dc6073cb..a0574db994 100644 --- a/packages/@uppy/core/src/Uppy.test.js +++ b/packages/@uppy/core/src/Uppy.test.js @@ -1804,18 +1804,8 @@ describe('src/Core', () => { const validateRestrictions1 = core.validateRestrictions(newFile) const validateRestrictions2 = core2.validateRestrictions(newFile) - expect(validateRestrictions1).toMatchObject( - { - result: false, - reason: 'This file is smaller than the allowed size of 293 KB', - }, - ) - expect(validateRestrictions2).toMatchObject( - { - result: false, - reason: 'You can only upload: image/png', - }, - ) + expect(validateRestrictions1.message).toEqual('This file is smaller than the allowed size of 293 KB') + expect(validateRestrictions2.message).toEqual('You can only upload: image/png') }) it('should emit `restriction-failed` event when some rule is violated', () => { diff --git a/packages/@uppy/provider-views/src/Browser.jsx b/packages/@uppy/provider-views/src/Browser.jsx index 72d0a03a97..6c0e1b97e3 100644 --- a/packages/@uppy/provider-views/src/Browser.jsx +++ b/packages/@uppy/provider-views/src/Browser.jsx @@ -101,7 +101,7 @@ function Browser (props) { })} {files.map((file) => { - const validated = validateRestrictions( + const restrictionError = validateRestrictions( remoteFileObjToLocal(file), [...uppyFiles, ...currentSelection], ) @@ -119,8 +119,8 @@ function Browser (props) { viewType, i18n, type: 'file', - isDisabled: !validated.result && !isChecked(file), - restrictionReason: validated.reason, + isDisabled: restrictionError && !isChecked(file), + restrictionError, }) })} diff --git a/packages/@uppy/provider-views/src/Item/components/GridLi.jsx b/packages/@uppy/provider-views/src/Item/components/GridLi.jsx index 395600255a..482352cec4 100644 --- a/packages/@uppy/provider-views/src/Item/components/GridLi.jsx +++ b/packages/@uppy/provider-views/src/Item/components/GridLi.jsx @@ -4,7 +4,7 @@ function GridListItem (props) { const { className, isDisabled, - restrictionReason, + restrictionError, isChecked, title, itemIconEl, @@ -18,7 +18,7 @@ function GridListItem (props) { return (
  • {!isCheckboxDisabled ? (