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: throw error on initialize fail #307

Merged
merged 6 commits into from
Jan 27, 2025

Conversation

francescoopiccoli
Copy link
Contributor

@francescoopiccoli francescoopiccoli commented Jan 24, 2025

Problem

Follow up to the discussion in this merged PR: #306

In this PR: we revert accessing aws object safely, and return a ResponseError if initialization fails.

The previous PR (#306) was mistakenly trying to both mitigate and log the issue, when only one of the two objectives is possible since they are contrasting.
As stated in this comment (#307 (comment)) we will proceed with only logging since it will help in finding the root cause with the issue of aws object being undefined.

Solution

  • Remove optional chaining when accessing aws
  • Make sure to throw error even after catching it for logging purpose, this way make sure that LSP server won't start in case of error in initialization.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@justinmk3
Copy link

justinmk3 commented Jan 24, 2025

#306 was hard to review partly because of the lack of a test. Is there a test for init scenarios, or why not?

"perf" implies this is a performance related improvement. But this is more like a bug fix.

@justinmk3
Copy link

This PR should also improve the try-catch as mentioned in #306 (comment)

@francescoopiccoli francescoopiccoli changed the title perf: throw error on initialize fail fix: throw error on initialize fail Jan 24, 2025
@francescoopiccoli
Copy link
Contributor Author

francescoopiccoli commented Jan 24, 2025

#306 was hard to review partly because of the lack of a test. Is there a test for init scenarios, or why not?

"perf" implies this is a performance related improvement. But this is more like a bug fix.

@justinmk3 Thanks for reviewing. I changed the "perf" to "fix" as suggested.
You are right about adding tests, it would be beneficial, we will address it in a follow up PR to merge the fix in the meanwhile.

@volodkevych volodkevych self-requested a review January 24, 2025 15:30
@francescoopiccoli
Copy link
Contributor Author

francescoopiccoli commented Jan 24, 2025

After discussion with @volodkevych and @imykhai, we realized that either we mitigate or we log the failures to help toolkit find the root cause of the issue. Hence, we will revert the current changes to make sure to log any failure to aws being undefined.

return
return new ResponseError<InitializeError>(
ErrorCodes.InternalError,
error instanceof Error ? error.message : 'Unknown initialization error'

Choose a reason for hiding this comment

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

Please decorate the returned error message with

initialization options: ${JSON.stringify(params.initializationOptions)}`

This may seem repetitive, but what happens in line 108 and line 111 end up surfacing in different locations in the client, and users are more likely to give us the toolkit log, where this message is written. More importantly, we will receive this (line 111) string in our metrics, and this is the change I was initially asking for.

Copy link

@awschristou awschristou left a comment

Choose a reason for hiding this comment

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

Before proceeding, I'd like to see if we can get the initialize payload sent as part of the initialize response.

Copy link

@justinmk3 justinmk3 left a comment

Choose a reason for hiding this comment

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

The try still wraps too much code. I guess that can be a followup, like the test coverage.

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.

6 participants