Skip to content

Commit 8aabf74

Browse files
committed
Change to improve error messages
1 parent 8b1ff41 commit 8aabf74

4 files changed

Lines changed: 16 additions & 10 deletions

File tree

‎lib/ast-to-react.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ function toReact(state, node, index, parent) {
193193

194194
if(!basic&&typeofcomponent!=='function'){
195195
thrownewError(
196-
`Component for name \`${name}\` not defined or is not renderable`
196+
'Unexpected value `'+
197+
component+
198+
'` for `'+
199+
name+
200+
'`, expected component or tag name'
197201
)
198202
}
199203

‎lib/react-markdown.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,19 @@ export function ReactMarkdown(options) {
180180
)
181181
}
182182

183-
consthastNode=processor.runSync(processor.parse(file),file)
183+
consthastTree=processor.runSync(processor.parse(file),file)
184184

185-
if(hastNode.type!=='root'){
186-
thrownewTypeError('Expected a `root` node')
185+
if(hastTree.type!=='root'){
186+
thrownewTypeError(
187+
'Unexpected `'+hastTree.type+'` node, expected `root`'
188+
)
187189
}
188190

189191
/** @type {ReactElement} */
190192
letresult=React.createElement(
191193
React.Fragment,
192194
{},
193-
childrenToReact({options,schema: html,listDepth: 0},hastNode)
195+
childrenToReact({options,schema: html,listDepth: 0},hastTree)
194196
)
195197

196198
if(options.className){

‎lib/rehype-filter.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function rehypeFilter(options) {
2222
){
2323
if(options.allowedElements&&options.disallowedElements){
2424
thrownewTypeError(
25-
'Only one of `allowedElements` and `disallowedElements` should be defined'
25+
'Unexpected combined `allowedElements` and `disallowedElements`, expected one or the other'
2626
)
2727
}
2828

‎test/test.jsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ test('react-markdown', async function (t) {
558558
disallowedElements={['a']}
559559
/>
560560
)
561-
},/onlyoneof/i)
561+
},/Unexpectedcombined`allowedElements`and`disallowedElements`,expectedoneortheother/)
562562
}
563563
)
564564

@@ -631,7 +631,7 @@ test('react-markdown', async function (t) {
631631
)
632632
})
633633

634-
awaitt.test('should fail on invalid component',function(){
634+
awaitt.test('should fail on an invalid component',function(){
635635
assert.throws(function(){
636636
asHtml(
637637
<Markdown
@@ -642,7 +642,7 @@ test('react-markdown', async function (t) {
642642
}}
643643
/>
644644
)
645-
},/Componentforname`h1`/)
645+
},/Unexpectedvalue`123`for`h1`,expectedcomponentortagname/)
646646
})
647647

648648
awaitt.test('should support `null`, `undefined` in components',function(){
@@ -1204,7 +1204,7 @@ test('react-markdown', async function (t) {
12041204
awaitt.test('should fail on a plugin replacing `root`',function(){
12051205
assert.throws(function(){
12061206
asHtml(<Markdownchildren="a"rehypePlugins={[plugin]}/>)
1207-
},/Expecteda`root`node/)
1207+
},/Unexpected`comment`node,expected`root/)
12081208

12091209
functionplugin(){
12101210
/**

0 commit comments

Comments
 (0)