Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot read properties of undefined (reading 'range') #486

Open
CristhianMotoche opened this issue Nov 29, 2024 · 0 comments
Open

Comments

@CristhianMotoche
Copy link

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

  1. Go to the CodeHike playground: https://stackblitz.com/github/code-hike/v1-starter?file=app%2Fpage.mdx
  2. 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant