Skip to content
This repository was archived by the owner on Sep 28, 2025. It is now read-only.

Commit 977dbdd

Browse files
authored
fix: ensure property is safely accessed in getJsonPath function (#800)
1 parent 1519caf commit 977dbdd

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

server/src/lib/lsp/completion/service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ export class CompletionService extends BaseService implements Partial<IService>
8383
};
8484
} catch (err: any) {
8585
const code = ErrorCodes.CompletionService + (err.code ?? 0);
86-
87-
return new ResponseError<void>(code, `error on ${filename}, error: ` + JSON.stringify(err, undefined, 2));
86+
87+
// Somehow just stringifying the error returns an empty object, so I make sure message and stack are always there
88+
return new ResponseError<void>(code, `error on ${filename}, error: ` + JSON.stringify({...err, message: err.message, stack: err.stack}, undefined, 2));
8889
} finally {
8990
this.logger.debug(`exiting on: ${filename}`);
9091
workDoneProgress.done();

server/src/lib/minecraft/json/path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function getJsonPath(cursor: number, text: string | TextDocument): Path {
1515
const pos = jsonc.getLocation(text, cursor);
1616

1717
return {
18-
property: pos.path[pos.path.length - 1].toString(),
18+
property: (pos.path[pos.path.length - 1] ?? '').toString(),
1919
path: pos.path.join("/"),
2020
isProperty: !pos.isAtPropertyKey,
2121
};

0 commit comments

Comments
 (0)