Skip to content

Commit

Permalink
Add context to error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Jan 20, 2025
1 parent 7c8e255 commit c4b2c23
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
6 changes: 4 additions & 2 deletions bundles/datastar-core.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions bundles/datastar-core.js.map

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions bundles/datastar.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions bundles/datastar.js.map

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions library/src/engine/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ import { type InitContext, PluginType, type RuntimeContext } from './types'
// const url = 'https://data-star.dev/errors'
const url = `${window.location.origin}/errors`

function dserr(type: string, reason: string, metadata = {}) {
interface Metadata {
error?: string;
[key: string]: any;
}

function dserr(type: string, reason: string, metadata: Metadata = {}) {
const e = new Error()
reason = reason[0].toUpperCase() + reason.slice(1)
e.name = `${DATASTAR} ${type} error ${reason}`
e.name = `${DATASTAR} ${type} error`
const r = kebabize(reason).replaceAll('-', '_')
const q = new URLSearchParams({
metadata: JSON.stringify(metadata),
}).toString()
e.message = `for more info see ${url}/${type}/${r}?${q}`
const c = JSON.stringify(metadata, null, 2)
e.message = `${reason}\nMore info: ${url}/${type}/${r}?${q}\nContext: ${c}`
return e
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/go/consts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c4b2c23

Please sign in to comment.