Skip to content
This repository was archived by the owner on Nov 6, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/client/api/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Observable, Subscription } from 'rxjs'
import { createProxyAndHandleRequests } from '../../common/proxy'
import { ExtConfigurationAPI } from '../../extension/api/configuration'
import { ConfigurationUpdateParams } from '../../protocol'
import { Connection } from '../../protocol/jsonrpc2/connection'
import { Connection, ConnectionError, ConnectionErrors } from '../../protocol/jsonrpc2/connection'

/** @internal */
export interface ClientConfigurationAPI {
Expand All @@ -26,7 +26,14 @@ export class ClientConfiguration<C> implements ClientConfigurationAPI {

this.subscriptions.add(
environmentConfiguration.subscribe(config => {
this.proxy.$acceptConfigurationData(config)
this.proxy.$acceptConfigurationData(config).catch(error => {
if (error instanceof ConnectionError && error.code === ConnectionErrors.Unsubscribed) {
// This error was probably caused by the user disabling
// an extension, which is a normal occurrence.
return
}
throw error
})
})
)
}
Expand Down
5 changes: 3 additions & 2 deletions src/extension/api/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ExtConfigurationSection<C extends object> implements sourcegraph.Configura
* @template C - The configuration schema.
*/
export interface ExtConfigurationAPI<C> {
$acceptConfigurationData(data: Readonly<C>): void
$acceptConfigurationData(data: Readonly<C>): Promise<void>
}

/**
Expand All @@ -48,8 +48,9 @@ export class ExtConfiguration<C extends ConfigurationCascade<any>> implements Ex

constructor(private proxy: ClientConfigurationAPI) {}

public $acceptConfigurationData(data: Readonly<C>): void {
public $acceptConfigurationData(data: Readonly<C>): Promise<void> {
this.data.next(Object.freeze(data))
return Promise.resolve()
}

public get(): sourcegraph.Configuration<C> {
Expand Down
14 changes: 10 additions & 4 deletions src/protocol/jsonrpc2/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const NullLogger: Logger = Object.freeze({
},
})

enum ConnectionErrors {
export enum ConnectionErrors {
/**
* The connection is closed.
*/
Expand All @@ -63,7 +63,7 @@ enum ConnectionErrors {
AlreadyListening = 3,
}

class ConnectionError extends Error {
export class ConnectionError extends Error {
public readonly code: ConnectionErrors

constructor(code: ConnectionErrors, message: string) {
Expand Down Expand Up @@ -632,9 +632,15 @@ function _createConnection(transports: MessageTransports, logger: Logger, strate
}
state = ConnectionState.Unsubscribed
unsubscribeEmitter.fire(undefined)
const error = new Error('Connection got unsubscribed.')
for (const key of Object.keys(responsePromises)) {
responsePromises[key].reject(error)
responsePromises[key].reject(
new ConnectionError(
ConnectionErrors.Unsubscribed,
`The underlying JSON-RPC connection got unsubscribed while responding to this ${
responsePromises[key].method
} request.`
)
)
}
responsePromises = Object.create(null)
requestTokens = Object.create(null)
Expand Down