8000 [#245] catch all exceptions during yaml parsing by ghentschke · Pull Request #246 · eclipse-cdt/cdt-lsp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[#245] catch all exceptions during yaml parsing #246

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

Merged
merged 4 commits into from
Feb 6, 2024

Conversation

ghentschke
Copy link
Contributor
@ghentschke ghentschke commented Feb 5, 2024

- Move showErrorMessage method from LSpUtils to ClangdConfigurationFileManager since it's only used here. Despite that we do not want to publish the LspUtils when making the org.eclipse.cdt.lsp.clangd package public API.

Do not set compilation database path in .clangd file with invalid yaml syntax.

fixes #245

- Move showErrorMessage method from LSpUtils to
ClangdConfigurationFileManager since it's only used here. Despite that
we do not want to publish the LspUtils when making the
org.eclipse.cdt.lsp.clangd package public API.
var status = new Status(IStatus.ERROR, ClangdPlugin.PLUGIN_ID, e.getMessage());
var projectLocation = project.getLocation().addTrailingSeparator().toPortableString();
LspUtils.showErrorMessage(LspEditorUiMessages.CProjectChangeMonitor_yaml_scanner_error,
LspEditorUiMessages.CProjectChangeMonitor_yaml_scanner_error_message + projectLocation
showErrorDialog(LspEditorUiMessages.ClangdConfigurationFileManager_yaml_error,
Copy link
Member

Choose a reason for hiding this comment

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

But it should be a headless component implementation. Why does it show any dialogs at all?

Copy link
Member

Choose a reason for hiding this comment

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

Since this is a component, you can try to bind org.eclipse.e4.core.services.statusreporter.StatusReporter and report through it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But it should be a headless component implementation. Why does it show any dialogs at all?

Users can edit the the .clangd file manually to add more options. If they add failures, it will be revealed when the .clangd file gets updated.

Copy link
Contributor Author
@ghentschke ghentschke Feb 5, 2024

Choose a reason for hiding this comment

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

Since this is a component, you can try to bind org.eclipse.e4.core.services.statusreporter.StatusReporter and report through it.

yes. I'll check that. Thanks for the hint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Users can edit the the .clangd file manually to add more options. If they add failures, i 8000 t will be revealed when the .clangd file gets updated.

Maybe it's better to add a listener when the file gets edited and validate it (e.g. by loading it and showing an error dialog if the load fails).

Copy link
Member

Choose a reason for hiding this comment

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

Users can edit the the .clangd file manually to add more options. If they add failures, it will be revealed when the .clangd file gets updated.

But this is different story. If user initiated all the chain from UI, we need to throw an exception from this method and show it to the user in UI layer. In this case you don't need more services, just throw

}

private static Shell getActiveShell() {
if (PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null)
Copy link
Member

Choose a reason for hiding this comment

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

PlatformUI.getWorkbench() != null

This code will not work as expected for not initialized workbench
But the issue is different: please avoid static calls from dynamic context, there will be no good. If you hrdly need workbench - please bind it as a service. However, I believe this service does not need UI, see my comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However, I believe this service does not need UI

When I think about it, I have to agree with you. Check if the user edits the .clangd file properly should be done somewhere else.

- remove error dialog since it does not belong to the
ClangdConfigurationFileManager. The check, if the user edits the .clangd
file properly should be done somewhere else.
@ghentschke ghentschke requested a review from ruspl-afed February 5, 2024 20:04
Copy link
Member
@ruspl-afed ruspl-afed left a comment

Choose a reason for hiding this comment

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

Although my suggestion was to throw an exception from setCompilationDatabase method (up to the UI "call site") instead of showing error dialog inside it, I'm happy to see dialog invocation removed from the headless code.

- do not set database path in .clangd file with invalid yaml syntax. The
user has to fix it first.
@ghentschke ghentschke merged commit 61be8ca into eclipse-cdt:master Feb 6, 2024
@ghentschke
Copy link
Contributor Author

@ruspl-afed thank you for the very constructive review!

@ghentschke
Copy link
Contributor Author

Although my suggestion was to throw an exception from setCompilationDatabase method (up to the UI "call site")

Unfortunately there is no UI "call site" since it's an event handler call. That's why I opened #247 .

@ghentschke ghentschke added this to the 1.1.0 milestone Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Yaml syntax errors in .clangd file leads to unhandled exception
2 participants
0