Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Show an error notification when misconfigured #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chrismwendt
Copy link
Contributor

@chrismwendt chrismwendt commented May 4, 2019

When your go.serverUrl is wrong, you'll see:

image

When your go.sourcegraphUrl is wrong, you'll see:

image

@ryan-blunden Any feedback on this second error message?

The icon links to https://sourcegraph.com/extensions/sourcegraph/go

image

Only admins see these error notifications.

cc @ryan-blunden who wordsmithed the first error message

const conn = createWebSocketConnection(wsrpc.toSocket(webSocket), new ConsoleLogger())
webSocket.addEventListener('open', () => resolve(conn))
webSocket.addEventListener('error', event => reject(new Error(connectingToGoLangserverHelp)))
webSocket.addEventListener('error', event => {
notifyUnableToConnectToLanguageServer(address)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems redundant - this rejects the Promise, which is caught in the catch Block, where this function is also called. In general it's not good to have this logic in the event handler because if notifyUnableToConnectToLanguageServer throws itself for some reason that error will not be propagated and the Promise will be pending forever.

webSocket.addEventListener('error', event => {
notifyUnableToConnectToLanguageServer(address)
reject(event)
})
} catch (e) {
if ('message' in e && /Failed to construct/.test(e.message)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This err.message check (as any err.message check really) seems really brittle. What case is it trying to detect? Which case is it trying to not detect?

For example, I notice that it gets triggered in Chrome when you pass an http:// URL. Firefox however has a different Error message for that case. It also does not get triggered for an unsuccessful connection, or for passing an invalid URL.

].join('\n')

const connection = (await new Promise((resolve, reject) => {
const connection = (await new Promise<wsrpc.MessageConnection>((resolve, reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should use an async IIFE instead of the Promise constructor (Promise constructor should be avoided where possible, and it's possible here)

console.error(connectingToSourcegraphHelp)
if (
'message' in e &&
(/no such host/.test(e.message) || /i\/o timeout/.test(e.message) || /connection refused/.test(e.message))
Copy link
Contributor

Choose a reason for hiding this comment

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

Where do these errors come from? How can we be confident that these error messages are reliable? Are there no error codes/types, and if not, can we add them?

Which errors can happen that should not pass through this?

'codeIntel.error.link': 'https://sourcegraph.com/extensions/sourcegraph/go',
})
const portByProtocol: { [protocol: string]: string } = { 'wss:': '443', 'ws:': '80' }
sourcegraph.app.activeWindow!.showNotification(
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's an error message, it should use NotificationType.Error

let webSocket: WebSocket
try {
webSocket = new WebSocket(address.href)
} catch (e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This error would get caught by the outer catch, which has the same handling, so this try/catch appears redundant

notifyUnableToConnectToLanguageServer(address)
return
}
webSocket.addEventListener('open', () => resolve())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
webSocket.addEventListener('open', () => resolve())
webSocket.addEventListener('open', resolve)

return
}
webSocket.addEventListener('open', () => resolve())
webSocket.addEventListener('error', error => reject(error))
Copy link
Contributor

Choose a reason for hiding this comment

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

error is not an Error, it's an Event - always reject with Error instances

)
}

async function canary(address: URL): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a doc comment? It's not obvious to me what this function's job is (maybe I just don't understand the name)

`- Comment out **\`go.serverUrl\`** in your [global settings](${
sourcegraph.internal.sourcegraphURL
}site-admin/global-settings).`,
].join('\n')
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice use of markdown

@felixfbecker
Copy link
Contributor

This looks like yet another thing that we should have for all language extensions/servers, not just Go. It should be added to lsp-client

@chrismwendt
Copy link
Contributor Author

Thanks for the useful feedback 🙇

If we can get lsp-client integrated soon, I'll migrate this PR to lsp-client and then simply bump the version in sourcegraph-go.

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.

2 participants