Better error logging

Hi, I am trying to log the errors in a better way to include the stack trace on the logs. When I checked the docs, (https://developers.cloudflare.com/workers/observability/source-maps/), once source maps are enabled, we would see the trace with respect to the source maps. But after enabling, I am still seeing the trace with respect to the minified version (js). Here is the logs I got, and my wrangler.toml looks like:
name = "name"
main = "src/index.ts"
compatibility_date = "2025-04-01"
upload_source_maps = true

compatibility_flags = ["nodejs_compat"]

[observability]
enabled = true
# other env releated...
name = "name"
main = "src/index.ts"
compatibility_date = "2025-04-01"
upload_source_maps = true

compatibility_flags = ["nodejs_compat"]

[observability]
enabled = true
# other env releated...
My log function looks like:
export function captureError(e: unknown) {
if (e instanceof Error) {
console.error('Captured unhandled error:', e, '\nStack:', e.stack);
} else {
console.error('Captured unhandled error (non-Error):', e);
}
}
export function captureError(e: unknown) {
if (e instanceof Error) {
console.error('Captured unhandled error:', e, '\nStack:', e.stack);
} else {
console.error('Captured unhandled error (non-Error):', e);
}
}
Not sure, why its showing the logs with the javascript version.
No description
2 Replies
Walshy
Walshy4w ago
Source maps are for uncaught exceptions. Catching them doesn't remap sadly today
blackfish
blackfishOP4w ago
Oh okay. Actually my usage was particularly to log uncaught errors, but if you see this screenshot, it just logs the error, not the stack/ trace. This error was not caught anywhere
No description

Did you find this page helpful?