Skip to content

Commit 3be2840

Browse files
committed
refactor: print error messages in the debug mode
1 parent 187e12e commit 3be2840

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

packages/keybr-assets/lib/context.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ export const ManifestContext = createContext<Manifest>(null!);
66
export function useManifest(): Manifest {
77
const value = useContext(ManifestContext);
88
if (value == null) {
9-
throw new Error();
9+
throw new Error(
10+
process.env.NODE_ENV !== "production"
11+
? "ManifestContext is missing"
12+
: undefined,
13+
);
1014
}
1115
return value;
1216
}

packages/keybr-keyboard/lib/context.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ export const KeyboardContext = createContext<Keyboard>(null!);
99
export function useKeyboard(): Keyboard {
1010
const value = useContext(KeyboardContext);
1111
if (value == null) {
12-
throw new Error();
12+
throw new Error(
13+
process.env.NODE_ENV !== "production"
14+
? "KeyboardContext is missing"
15+
: undefined,
16+
);
1317
}
1418
return value;
1519
}

packages/keybr-pages-shared/lib/pagedata.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export const PageDataContext = createContext<PageData>(null!);
2727
export function usePageData(): PageData {
2828
const value = useContext(PageDataContext);
2929
if (value == null) {
30-
throw new Error();
30+
throw new Error(
31+
process.env.NODE_ENV !== "production"
32+
? "PageDataContext is missing"
33+
: undefined,
34+
);
3135
}
3236
return value;
3337
}

packages/keybr-phonetic-model/lib/context.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ export const PhoneticModelContext = createContext<PhoneticModel>(null!);
66
export function usePhoneticModel(): PhoneticModel {
77
const value = useContext(PhoneticModelContext);
88
if (value == null) {
9-
throw new Error();
9+
throw new Error(
10+
process.env.NODE_ENV !== "production"
11+
? "PhoneticModelContext is missing"
12+
: undefined,
13+
);
1014
}
1115
return value;
1216
}

packages/keybr-result/lib/context.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ export const ResultContext = createContext<ResultContextProps>(null!);
1212
export function useResults(): ResultContextProps {
1313
const value = useContext(ResultContext);
1414
if (value == null) {
15-
throw new Error();
15+
throw new Error(
16+
process.env.NODE_ENV !== "production"
17+
? "ResultContext is missing"
18+
: undefined,
19+
);
1620
}
1721
return value;
1822
}

packages/keybr-settings/lib/context.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ export const SettingsContext = createContext<SettingsContextProps>(null!);
1111
export function useSettings(): SettingsContextProps {
1212
const value = useContext(SettingsContext);
1313
if (value == null) {
14-
throw new Error();
14+
throw new Error(
15+
process.env.NODE_ENV !== "production"
16+
? "SettingsContext is missing"
17+
: undefined,
18+
);
1519
}
1620
return value;
1721
}

0 commit comments

Comments
 (0)