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

[CCI] Fix type errors in i18n #3629

Merged
merged 7 commits into from
Mar 30, 2023

Conversation

Nicksqain
Copy link
Contributor

@Nicksqain Nicksqain commented Mar 17, 2023

Description

  • Corrects error types of error handlers.
  • Corrects type errors for i18n and its configs.
  • Setting the type of the context for each of the helper functions and the list.

Issues Resolved

#3027

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
    • yarn test:ftr
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

@Nicksqain Nicksqain requested a review from a team as a code owner March 17, 2023 16:25
@ashwin-pc ashwin-pc added the OSCI Open Source Contributor Initiative label Mar 17, 2023
Copy link
Member

@ashwin-pc ashwin-pc left a comment

Choose a reason for hiding this comment

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

I like this PR, great job! just a few small comments but mostly there 😄

Comment on lines 73 to 88
} catch (error: unknown) {
if (error instanceof Error) {
if (error instanceof parser.SyntaxError) {
if (error.name === 'SyntaxError') {
const errorWithContext = createParserErrorMessage(message, {
loc: {
line: error.location.start.line,
column: error.location.start.column - 1,
},
message: error.message,
});
throw errorWithContext;
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this nesting required? Cant you simply change the if condition to

if (error instanceof parser.SyntaxError && error.name === 'SyntaxError') {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if the error would be instance of parser.SyntaxError, so I left it so to get your opinion. I'll change it if it's right

task: ({ config }) =>
new Listr(extractDefaultMessages(config, srcPaths), { exitOnError: true }),
task: ({ config }) => {
return new Listr(extractDefaultMessages(config!, srcPaths), { exitOnError: true });
Copy link
Member

Choose a reason for hiding this comment

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

You are already handling for a missing config value in the extractDefaultMessages task, you dont need this change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can skipOnNoTranslations do a throw error if there is no config? So as not to create more checks. Although these functions will be used anyway and there is no other way to check if the config is in one place

src/dev/run_i18n_check.ts Outdated Show resolved Hide resolved
src/dev/run_i18n_check.ts Show resolved Hide resolved
{
title: 'Merging .i18nrc.json files',
task: () => new Listr(mergeConfigs(includeConfig), { exitOnError: true }),
},
{
title: 'Extracting Default Messages',
task: ({ config }) =>
new Listr(extractDefaultMessages(config, srcPaths), { exitOnError: true }),
new Listr(extractDefaultMessages(config!, srcPaths), { exitOnError: true }),
Copy link
Member

Choose a reason for hiding this comment

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

same here, you dont need this change

config,
log,
});
if (config) {
Copy link
Member

Choose a reason for hiding this comment

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

I like you pattern of throwing an error if config is missing instead of this

Copy link
Member

Choose a reason for hiding this comment

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

Looks like you missed this change. The reason i like throwing an error is because it makes it clear why the task failed. The config should never be empty, but if it is, based on this change this task will complete silently, but the other tasks like checkCompatibility will throw an error. And since we expect config to be defined in this task, I want to know if it did not run.

@ashwin-pc ashwin-pc self-assigned this Mar 17, 2023
@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2023

Codecov Report

Merging #3629 (efbcbdb) into main (e871aea) will decrease coverage by 0.07%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #3629      +/-   ##
==========================================
- Coverage   66.46%   66.39%   -0.07%     
==========================================
  Files        3205     3209       +4     
  Lines       61562    61633      +71     
  Branches     9497     9506       +9     
==========================================
+ Hits        40916    40924       +8     
- Misses      18375    18425      +50     
- Partials     2271     2284      +13     
Flag Coverage Δ
Linux 66.39% <100.00%> (-0.01%) ⬇️
Windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/dev/i18n/integrate_locale_files.ts 76.81% <ø> (ø)
src/dev/i18n/utils/verify_icu_message.ts 80.00% <100.00%> (ø)

... and 52 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@kavilla kavilla linked an issue Mar 20, 2023 that may be closed by this pull request
@joshuarrrr
Copy link
Member

@Nicksqain When you add the next commits based on the review feedback, please also add an entry to the CHANGELOG.md file (under the "Refactoring" section).

@Nicksqain Nicksqain requested a review from ashwin-pc March 24, 2023 12:08
Copy link
Member

@ashwin-pc ashwin-pc left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes @Nicksqain. Just a few last comments and this PR should be good to merge :)

@@ -35,7 +35,7 @@ import { resolve } from 'path';
import { createFailError, run } from '@osd/dev-utils';
import { ErrorReporter, serializeToJson, serializeToJson5, writeFileAsync } from './i18n';
import { extractDefaultMessages, mergeConfigs } from './i18n/tasks';

import { ListrContext } from './run_i18n_check';
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This can come from a common source instead of another file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not know how you import :(
What is considered a common source?

Copy link
Contributor Author

@Nicksqain Nicksqain Mar 28, 2023

Choose a reason for hiding this comment

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

./i18n/tasks. Right?

{
title: 'Merging .i18nrc.json files',
task: () => new Listr(mergeConfigs(includeConfig), { exitOnError: true }),
},
{
title: 'Extracting Default Messages',
task: ({ config }) =>
new Listr(extractDefaultMessages(config, srcPaths), { exitOnError: true }),
new Listr(extractDefaultMessages(config!, srcPaths), { exitOnError: true }),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
new Listr(extractDefaultMessages(config!, srcPaths), { exitOnError: true }),
new Listr(extractDefaultMessages(config, srcPaths), { exitOnError: true }),

update extractDefaultMessages to accept an optional config just like checkCompatibility. This should never happen based on the order that they are called in, but should the order ever be swapped, the error will point us to the problem

config,
log,
});
if (config) {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you missed this change. The reason i like throwing an error is because it makes it clear why the task failed. The config should never be empty, but if it is, based on this change this task will complete silently, but the other tasks like checkCompatibility will throw an error. And since we expect config to be defined in this task, I want to know if it did not run.

@Nicksqain Nicksqain requested a review from ashwin-pc March 28, 2023 10:00
Copy link
Member

@ashwin-pc ashwin-pc left a comment

Choose a reason for hiding this comment

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

👍 Awesome job on your pull request! Thanks for the contribution! 🎉

@ashwin-pc
Copy link
Member

@Nicksqain I did notice however that typescript still complains about the verify_icu_message.ts file. Didnt want to block the PR because we can fix it later too, but just wanted to call that out.

@Nicksqain
Copy link
Contributor Author

Nicksqain commented Mar 29, 2023

@ashwin-pc Where exactly is the typescript error?
Maybe I'm checking for errors in the wrong way.
But I have no warnings or errors

@ashwin-pc
Copy link
Member

Screenshot 2023-03-29 at 10 33 19 AM

@Nicksqain
Copy link
Contributor Author

Nicksqain commented Mar 30, 2023

@ashwin-pc

Screenshot 2023-03-29 at 10 33 19 AM

I created an issue for this problem #3606
There are two solutions, but the second one is not bad either.

  • 1. We need to update dependencies for parser to solve this problem.
  • 2. I can solve it here too by applying template literals by concatenating all parser.SyntaxError arguments. What do you think?

@joshuarrrr
Copy link
Member

@Nicksqain Given #3606, I'd strongly prefer to update the deprecated dependency, so no need to account for it in this PR.

Copy link
Member

@joshuarrrr joshuarrrr left a comment

Choose a reason for hiding this comment

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

Thanks so much!

@joshuarrrr joshuarrrr merged commit fd61f7a into opensearch-project:main Mar 30, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 30, 2023
* Changes related to i18n configs
* Added changes to missed commits and also added tasks Listr interface to common source
* Update imports for other files that using ListrContext interface

Signed-off-by: Alexei Karikov <[email protected]>

---------

Signed-off-by: Alexei Karikov <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
(cherry picked from commit fd61f7a)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
vagimeli pushed a commit to vagimeli/OpenSearch-Dashboards that referenced this pull request Apr 4, 2023
* Changes related to i18n configs
* Added changes to missed commits and also added tasks Listr interface to common source
* Update imports for other files that using ListrContext interface

Signed-off-by: Alexei Karikov <[email protected]>

---------

Signed-off-by: Alexei Karikov <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
Signed-off-by: vagimeli <[email protected]>
joshuarrrr pushed a commit that referenced this pull request Apr 4, 2023
* Changes related to i18n configs
* Added changes to missed commits and also added tasks Listr interface to common source
* Update imports for other files that using ListrContext interface

Signed-off-by: Alexei Karikov <[email protected]>

---------

Signed-off-by: Alexei Karikov <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
(cherry picked from commit fd61f7a)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
sikhote pushed a commit to sikhote/OpenSearch-Dashboards that referenced this pull request Apr 24, 2023
* Changes related to i18n configs
* Added changes to missed commits and also added tasks Listr interface to common source
* Update imports for other files that using ListrContext interface

Signed-off-by: Alexei Karikov <[email protected]>

---------

Signed-off-by: Alexei Karikov <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
Signed-off-by: David Sinclair <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x OSCI Open Source Contributor Initiative v2.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix type errors in i18n
4 participants