Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax error message made more verbose #1462

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions ext/js/dictionary/dictionary-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,19 @@
const results = [];
for (const file of files) {
const content = await this._getData(file, new TextWriter());
/** @type {unknown} */
const entries = parseJson(content);
let entries;

try {
/** @type {unknown} */
entries = parseJson(content);
}

Check failure on line 823 in ext/js/dictionary/dictionary-importer.js

View workflow job for this annotation

GitHub Actions / Static Analysis

Closing curly brace does not appear on the same line as the subsequent block
catch (error) {
if (error instanceof Error) {
let newError = new Error(error.message + `. Dictionary has invalid data in '${file.filename}'`);

Check failure on line 826 in ext/js/dictionary/dictionary-importer.js

View workflow job for this annotation

GitHub Actions / Static Analysis

'newError' is never reassigned. Use 'const' instead
console.error(newError);

Check failure on line 827 in ext/js/dictionary/dictionary-importer.js

View workflow job for this annotation

GitHub Actions / Static Analysis

Unexpected console statement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use log.error instead. log is a wrapper around console.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Can you elaborate on what makes log.error more appropriate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check out https://github.com/themoeway/yomitan/blob/master/ext/js/core/log.js#L74. It basically formats the log with info for the extension.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, I don't think it's useful logging here and still letting the error propagate. If I decided to log the errors upstream, it would cause the error to be logged twice. You can remove the console.error entirely.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'll do away with it entirely.

throw newError;
}
}

startIndex = progressData.index;
this._progress();
Expand Down
Loading