Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add proper error message
  • Loading branch information
adamwathan committed May 13, 2022
commit f2d02c30bd366ae98fec1431a47992854dd284f3
8 changes: 6 additions & 2 deletions src/lib/setupContextUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,19 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
let result = variantFunction({ modifySelectors, container, separator })

if (typeof result === 'string' && !isValidVariantFormatString(result)) {
throw new Error("Custom variants must use a media query or provide an `&` to specify selector placement.")
throw new Error(
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
)
}

return result
}
}

if (!isValidVariantFormatString(variantFunction)) {
throw new Error("Custom variants must use a media query or provide an `&` to specify selector placement.")
throw new Error(
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
)
}

return parseVariant(variantFunction)
Expand Down
4 changes: 2 additions & 2 deletions tests/variants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe('custom advanced variants', () => {
}

await expect(run('@tailwind components;@tailwind utilities', config)).rejects.toThrowError(
"Custom variants must use a media query or provide an `&` to specify selector placement."
"Your custom variant `wtf-bbq` has an invalid format string. Make sure it's an at-rule or contains a `&` placeholder."
)
})

Expand All @@ -241,7 +241,7 @@ describe('custom advanced variants', () => {
}

await expect(run('@tailwind components;@tailwind utilities', config)).rejects.toThrowError(
"Custom variants must use a media query or provide an `&` to specify selector placement."
"Your custom variant `wtf-bbq` has an invalid format string. Make sure it's an at-rule or contains a `&` placeholder."
)
})
})
Expand Down