Skip to content
This repository was archived by the owner on Feb 20, 2026. It is now read-only.
This repository was archived by the owner on Feb 20, 2026. It is now read-only.

Add source mapping for errors in routes.match #216

@EECOLOR

Description

@EECOLOR

This can be done in the template (hacked version):

Object.assign(
  render,
  withSourceMap(template),
)

function withSourceMap(template) {
  console.log(template)
  return mapValues(template, x =>
    typeof x === 'function' ? (...args) => withSourceMappedErrorAsync(createMap, () => x(...args)) :
    x && typeof x === 'object' ? withSourceMap(x) : x
  )
}
function mapValues(x, f) {
  return Object.entries(x)
    .map(([k, v]) => [k, f(v, k, x)])
    .reduce((result, [k, v]) => ({ ...result, [k]: v }), {})
}
...
function withSourceMappedErrorAsync(createMap, fn, options) {
  return withRawErrorStackAsync(async () => {
    try {
      return await fn()
    } catch (e) {
      const messageWithStack = e + '\n' + toMappedStack(createMap, e.stack, options)
      const error = new Error(messageWithStack)
      error.stack = messageWithStack
      throw error
    }
  })
}
async function withRawErrorStackAsync(fn) {
  const $prepareStackTrace = Error.prepareStackTrace
  Error.prepareStackTrace = (error, stack) => stack
  try { return await fn() } finally { Error.prepareStackTrace = $prepareStackTrace }
}

Another option would be to call the function with source mapped error from serve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions