Skip to content

Commit c4f4ea0

Browse files
jjinuxgajus
authored andcommitted
feat: make it easier to debug mistakes (#179)
1 parent b2119fd commit c4f4ea0

4 files changed

+13
-11
lines changed

src/createObjectExpression.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const createObjectExpression = (t: BabelTypes, object: InputObjectType): ObjectE
2929
} else if (typeof value === 'boolean') {
3030
newValue = t.booleanLiteral(value);
3131
} else {
32-
throw new TypeError('Unexpected type.');
32+
throw new TypeError('Unexpected type: ' + typeof value);
3333
}
3434

3535
properties.push(

src/getClassName.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,32 @@ const getClassNameForNamespacedStyleName = (
2828

2929
if (!moduleName) {
3030
if (handleMissingStyleName === 'throw') {
31-
throw new Error('Invalid style name.');
31+
throw new Error('Invalid style name: ' + styleName);
3232
} else if (handleMissingStyleName === 'warn') {
3333
// eslint-disable-next-line no-console
34-
console.warn('Invalid style name.');
34+
console.warn('Invalid style name: ' + styleName);
3535
} else {
3636
return null;
3737
}
3838
}
3939

4040
if (!styleModuleImportMap[importName]) {
4141
if (handleMissingStyleName === 'throw') {
42-
throw new Error('CSS module import does not exist.');
42+
throw new Error('CSS module import does not exist: ' + importName);
4343
} else if (handleMissingStyleName === 'warn') {
4444
// eslint-disable-next-line no-console
45-
console.warn('CSS module import does not exist.');
45+
console.warn('CSS module import does not exist: ' + importName);
4646
} else {
4747
return null;
4848
}
4949
}
5050

5151
if (!styleModuleImportMap[importName][moduleName]) {
5252
if (handleMissingStyleName === 'throw') {
53-
throw new Error('CSS module does not exist.');
53+
throw new Error('CSS module does not exist: ' + moduleName);
5454
} else if (handleMissingStyleName === 'warn') {
5555
// eslint-disable-next-line no-console
56-
console.warn('CSS module does not exist.');
56+
console.warn('CSS module does not exist: ' + moduleName);
5757
} else {
5858
return null;
5959
}
@@ -83,11 +83,13 @@ export default (styleNameValue: string, styleModuleImportMap: StyleModuleImportM
8383
}
8484

8585
if (styleModuleImportMapKeys.length === 0) {
86-
throw new Error('Cannot use styleName attribute without importing at least one stylesheet.');
86+
throw new Error('Cannot use styleName attribute for style name \'' + styleName +
87+
'\' without importing at least one stylesheet.');
8788
}
8889

8990
if (styleModuleImportMapKeys.length > 1) {
90-
throw new Error('Cannot use anonymous style name with more than one stylesheet import.');
91+
throw new Error('Cannot use anonymous style name \'' + styleName +
92+
'\' with more than one stylesheet import.');
9193
}
9294

9395
const styleModuleMap: StyleModuleMapType = styleModuleImportMap[styleModuleImportMapKeys[0]];

src/replaceJsxExpressionContainer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default (
8181
)
8282
));
8383
} else {
84-
throw new Error('Unexpected attribute value.');
84+
throw new Error('Unexpected attribute value: ' + destinationAttribute.value);
8585
}
8686
} else {
8787
path.node.openingElement.attributes.push(jSXAttribute(

src/resolveStringLiteral.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default (
4242
stringLiteral(resolvedStyleName)
4343
);
4444
} else {
45-
throw new Error('Unexpected attribute value.');
45+
throw new Error('Unexpected attribute value:' + destinationAttribute.value);
4646
}
4747

4848
path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(sourceAttribute), 1);

0 commit comments

Comments
 (0)