X Tutup
Skip to content

Commit f27fdcb

Browse files
authored
Merge branch 'TypeScriptToLua:master' into master
2 parents 77ba3cc + df3adb7 commit f27fdcb

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/lualib/Error.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ interface ErrorType {
33
new (...args: any[]): Error;
44
}
55

6-
function getErrorStack(constructor: () => any): string {
6+
function getErrorStack(constructor: () => any): string | undefined {
7+
// If debug module is not available in this environment, don't bother trying to get stack trace
8+
if (debug === undefined) return undefined;
9+
710
let level = 1;
811
while (true) {
912
const info = debug.getinfo(level, "f");
@@ -49,7 +52,7 @@ function initErrorClass(Type: ErrorType, name: string): any {
4952
export const Error: ErrorConstructor = initErrorClass(
5053
class implements Error {
5154
public name = "Error";
52-
public stack: string;
55+
public stack?: string;
5356

5457
constructor(public message = "") {
5558
this.stack = getErrorStack((this.constructor as any).new);

test/unit/error.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,22 @@ test.each([...builtinErrors, "CustomError"])("get stack from %s", errorType => {
324324
expect(stack).toMatch("innerFunction");
325325
expect(stack).toMatch("outerFunction");
326326
});
327+
328+
test("still works without debug module", () => {
329+
util.testFunction`
330+
try
331+
{
332+
throw new Error("hello, world");
333+
}
334+
catch (e)
335+
{
336+
return e;
337+
}
338+
`
339+
.setLuaHeader("debug = nil")
340+
.expectToEqual({
341+
message: "hello, world",
342+
name: "Error",
343+
stack: undefined,
344+
});
345+
});

0 commit comments

Comments
 (0)
X Tutup