Skip to content

Commit e9b50b4

Browse files
authoredDec 4, 2023
Improve error message for createStrictAPI() (#1571)
* chore: add new error message for strict api * chore: add changeset
1 parent 973596c commit e9b50b4

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed
 

‎.changeset/nervous-olives-appear.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compiled/react': patch
3+
---
4+
5+
Add custom error message to be shown when any output from createStrictAPI() is unexpectedly executed.

‎packages/react/src/create-strict-api/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { StrictCSSProperties, CSSPseudos } from '../types';
2-
import { createSetupError } from '../utils/error';
2+
import { createStrictSetupError } from '../utils/error';
33
import { type CompiledStyles, cx, type Internal$XCSSProp } from '../xcss-prop';
44

55
type PseudosDeclarations = {
@@ -210,14 +210,14 @@ type CompiledSchema = StrictCSSProperties & PseudosDeclarations;
210210
export function createStrictAPI<TSchema extends CompiledSchema>(): CompiledAPI<TSchema> {
211211
return {
212212
css() {
213-
throw createSetupError();
213+
throw createStrictSetupError();
214214
},
215215
cssMap() {
216-
throw createSetupError();
216+
throw createStrictSetupError();
217217
},
218218
cx,
219219
XCSSProp() {
220-
throw createSetupError();
220+
throw createStrictSetupError();
221221
},
222222
};
223223
}

‎packages/react/src/utils/error.ts

+20
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,23 @@ export const createSetupError = (): Error => {
1717
Good luck!
1818
`);
1919
};
20+
21+
export const createStrictSetupError = (): Error => {
22+
return new Error(`
23+
██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
24+
██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║██║ ██╔════╝██╔══██╗
25+
██║ ██║ ██║██╔████╔██║██████╔╝██║██║ █████╗ ██║ ██║
26+
██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║██║ ██╔══╝ ██║ ██║
27+
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗███████╗██████╔╝
28+
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝
29+
30+
@compiled/react
31+
32+
Code was executed when it shouldn't have. To resolve make sure to:
33+
34+
1. Set up Compiled.
35+
2. Configure importSources in your Compiled config to point to the module that exports the output of createStrictAPI().
36+
37+
For more information visit https://compiledcssinjs.com/docs/installation and follow the instructions.
38+
`);
39+
};

0 commit comments

Comments
 (0)
Please sign in to comment.