Skip to content

Instantly share code, notes, and snippets.

@Mistium
Created January 1, 2026 15:56
Show Gist options
  • Select an option

  • Save Mistium/3c587341d32d71d8da696becf4574c52 to your computer and use it in GitHub Desktop.

Select an option

Save Mistium/3c587341d32d71d8da696becf4574c52 to your computer and use it in GitHub Desktop.
Object.defineProperty(Error.prototype, "lineNumber", {
configurable: true,
enumerable: false,
get: function () {
if (!this.stack) return undefined;
const match = this.stack.match(/:(\d+):\d+\)?$/m);
return match ? Number(match[1]) : undefined;
}
});
try {
throw new Error("lmao")
} catch (e) {
console.log(e.lineNumber)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment