-
Notifications
You must be signed in to change notification settings - Fork 33
Description
When debugging #125 I noticed that stacktraces get lost if an error occurs when writing a compound tag. Instead of a helpful pointer to offending code, I got the following error from jest:
● NBT › #serialize › default › async
Failed: Object {
"message": "Require LongArray but found object",
"type": "IllegalInputType",
}
133 | //expect(value).toStrictEqual(src);
134 | });
> 135 | test("async", async () => {
| ^
136 | const src = new TestType();
137 | const buffer = await serialize(src, { compressed: compress });
138 | //expect(buffer).toBeTruthy();
at Env.it (node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:89:24)
at testNBT (packages/nbt/test.ts:135:13)
at Suite.describe (packages/nbt/test.ts:154:13)
at Suite.describe (packages/nbt/test.ts:153:9)
As you can probably imagine, this wasn't a fun one to debug 😓
The offending code:
minecraft-launcher-core-node/packages/nbt/index.ts
Lines 332 to 343 in 6b9dc80
| try { | |
| buf.writeByte(tagType); | |
| writeUTF8(buf, key); | |
| writer.write(buf, value, childContext); | |
| } catch (e) { | |
| if (e instanceof TypeError) { | |
| throw { | |
| type: "IllegalInputType", | |
| message: `Require ${TagType.getName(tagType)} but found ${typeof value}`, | |
| }; | |
| } | |
| } |
I think the stacktrace is lost because a 'plain object' is thrown instead of an actual Error. (I didn't even know you could do that, although I'm definitely not surprised.)
The (false) stacktrace that's listed in the log points to jest code that creates an Error instance. This is probably the error that causes the actual message in the log, thus creating a false stacktrace.