Open
Description
An annotation with ranges out of bounds throws an error that's not very descriptive. Is it possible to catch that error and throw an error with an easier message to understand?
Steps to reproduce
- Go to the CodeHike playground: https://stackblitz.com/github/code-hike/v1-starter?file=app%2Fpage.mdx
- Modify the first code sample with an annotation that includes a range that it's out of bounds. For example:
```js
const lorem = ipsum(dolor, sit)
// !mark(100)
const [amet, consectetur] = [0, 0]
lorem.adipiscing((sed, elit) => {
if (sed) {
amet += elit
}
})
```
Current behaviour:
Fails with:
Error: Cannot read properties of undefined (reading 'range')
Call Stack
range
node_modules/codehike/dist/code/lines.js (83:30)
applyBlockAnnotation
node_modules/codehike/dist/code/lines.js (55:17)
lines
node_modules/codehike/dist/code/pre.js (41:32)
ej
file:///home/projects/github-9xqabe/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (35:264151)
eval
file:///home/projects/github-9xqabe/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (35:276953)
Object.toJSON
file:///home/projects/github-9xqabe/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (35:281723)
stringify
<anonymous>
eval
file:///home/projects/github-9xqabe/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (35:268079)
ez
file:///home/projects/github-9xqabe/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (35:268158)
eH
file:///home/projects/github-9xqabe/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (35:268559)
Timeout.eval [as _onTimeout]
file:///home/projects/github-9xqabe/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (35:265057)
<unknown>
https://github9xqabe-kqha.w-credentialless-staticblitz.com/builtins.ddb8d84d.js (246:4692)
Expected behaviour:
I think it makes sense to throw an error but it would better if the error is more readable. Maybe something like:
Error: Cannot generate a valid range for the given code
Let me know if this makes sense. Thanks!
Metadata
Metadata
Assignees
Labels
No labels