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

Fix YAML Config Editing Console Runtime Errors by Switching to Yaml Library #289

Merged
merged 6 commits into from
Jan 22, 2024

Conversation

roshan-gh
Copy link
Contributor

@roshan-gh roshan-gh commented Jan 19, 2024

This pull request addresses the issue of multiple runtime errors generated during YAML config editing, attributed to the JS-yaml library. To enhance the user experience and provide more detailed error information, this PR replaces JS-yaml with the Yaml library. The Yaml library not only eliminates runtime errors but also includes comprehensive error details such as start line, end line, start column, and end column, facilitating better debugging and validation of YAML configurations.

Also, in the Yaml library, there are two options for displaying validation error messages:

1- Short Message:

Screenshot 2024-01-19 at 17 05 47 Screenshot 2024-01-19 at 17 06 04 Screenshot 2024-01-19 at 17 07 01

2- Long Message:

Screenshot 2024-01-19 at 17 10 27 Screenshot 2024-01-19 at 17 10 47 Screenshot 2024-01-19 at 17 11 08

For this pull request, a short message is implemented, but it can be changed as per the reviewers' request.

@roshan-gh roshan-gh linked an issue Jan 19, 2024 that may be closed by this pull request
Copy link

vercel bot commented Jan 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
otelbin ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 21, 2024 5:16pm

@roshan-gh roshan-gh changed the title Fix YAML Config Editing Runtime Errors by Switching to Yaml Library Fix YAML Config Editing Console Runtime Errors by Switching to Yaml Library Jan 19, 2024
@roshan-gh roshan-gh self-assigned this Jan 19, 2024
<div className={`${font.className} ${errorsStyle}`}>
<p className="max-w-[100%]">{`${jsYamlError.reason} ${
jsYamlError.mark && `(Line ${jsYamlError.mark.line})`
<p className="max-w-[100%]">{`${yamlError.code} ${
Copy link
Member

Choose a reason for hiding this comment

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

Question: Why are we using the short version here? IMHO that is hard to understand, and we seem have enough room in the console for the long version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, it will be change to the long version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The long version message is pushed and committed.

let jsonData: any;
try {
jsonData = YAML.parse(config, { logLevel: "error", schema: "failsafe" }) as any;
} catch (e) {}
Copy link
Member

Choose a reason for hiding this comment

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

Question: This silently catches and fully ignores the error. That seems dangerous to me. Why do we need to do this?

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 thought we were already displaying errors in the validation console; when editing the config, the console is overflowing with errors.

Copy link
Member

Choose a reason for hiding this comment

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

Could you please document this in the code in both locations? Because this empty catch block very much looks like a bug otherwise :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The related comments added to the code

const jsonData = useMemo(() => {
try {
return YAML.parse(value, { logLevel: "error", schema: "failsafe" }) as IConfig;
} catch (error: unknown) {}
Copy link
Member

Choose a reason for hiding this comment

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

Same question as above.

Copy link

sonarcloud bot commented Jan 21, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@bripkens bripkens merged commit d491dec into main Jan 22, 2024
9 of 10 checks passed
@bripkens bripkens deleted the 288-run-time-errors-when-editing-the-yaml-config branch January 22, 2024 08:52
@bripkens
Copy link
Member

LGTM 👍

@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run time errors when editing the YAML config
2 participants