Fix readJsonFile and add error handling
#15
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #14
The extension crashes on startup with the
Cannot convert undefined or null to objecterror. This is caused by theObject.keysinConfiguration::setLanguageConfigDefinitionsmethod because the config JSON file failed to parse in thereadJsonFileutil function which made the confignull.When the "jsonc-parser" package encounters a problem parsing the JSON via its
parsefunction, it just returnsnullinstead of erroring.The fix is to provide proper error handling, logging and showing a user error dialog when parse errors occur, directly from
readJsonFilefunction. If errors occur, the error will be thrown fromreadJsonFilewhich will fail extension startup and crash, this is to provide easier debugging, instead of waiting for subsequent code that relies on the function from crashing the extension with an unrelated error.If no errors occur but the JSON file still returns as
null, then thereadJsonFilefunction will return an empty object as a fallback.Changes:
Logger Refactor:
Loggerclass export with a singletonloggerexport inlogger.ts, and updates all imports and usages to use this singleton instead of passing aLoggerinstance around. This simplifies the codebase, centralizes logging, and enables multiple files to use the logger on the same instance.Configuration Initialization:
Configurationclass and its instantiation to no longer require a logger parameter, reflecting the new singleton logger usage.Improved JSON File Error Handling:
readJsonFileutility inutils.tsto provide detailed error messages — including file, line, and column — when JSON parsing fails. It also notifies the user via a VS Code error message and offers to open the output channel for more details, then throws an error to halt execution.Utility Function Enhancement:
constructJsonParseErrorMsghelper function to format JSON parse errors for improved debugging and user feedback.