Skip to content

Commit eb52df2

Browse files
hlshenjoehan
andauthored
fix behaviour on failed postgres connection (#7287)
Co-authored-by: joehan <joehanley@google.com>
1 parent ccc2449 commit eb52df2

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

firebase-vscode/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## NEXT
22

3+
- Fix behaviour on failed postgres connection
4+
35
## 0.2.5
46

57
- Icon fix

firebase-vscode/src/data-connect/emulator-stream.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fetch from "node-fetch";
33
import { Observable, of } from "rxjs";
44
import { backOff } from "exponential-backoff";
55
import { ResolvedDataConnectConfigs } from "./config";
6+
import { Signal } from "@preact/signals-core";
67

78
enum Kind {
89
KIND_UNSPECIFIED = "KIND_UNSPECIFIED",
@@ -28,19 +29,20 @@ export const emulatorOutputChannel =
2829
vscode.window.createOutputChannel("Firebase Emulators");
2930

3031
/**
31-
*
32+
* TODO: convert to class
3233
* @param fdcEndpoint FDC Emulator endpoint
3334
*/
3435
export async function runEmulatorIssuesStream(
3536
configs: ResolvedDataConnectConfigs,
3637
fdcEndpoint: string,
38+
isPostgresEnabled: Signal<boolean>,
3739
) {
3840
const obsErrors = await getEmulatorIssuesStream(configs, fdcEndpoint);
3941
const obsConverter = {
4042
next(nextResponse: EmulatorIssueResponse) {
4143
if (nextResponse.result?.issues?.length) {
4244
for (const issue of nextResponse.result.issues) {
43-
displayIssue(issue);
45+
displayAndHandleIssue(issue, isPostgresEnabled);
4446
}
4547
}
4648
},
@@ -57,14 +59,19 @@ export async function runEmulatorIssuesStream(
5759
/**
5860
* Based on the severity of the issue, either log, display notification, or display interactive popup to the user
5961
*/
60-
export function displayIssue(issue: EmulatorIssue) {
62+
export function displayAndHandleIssue(issue: EmulatorIssue, isPostgresEnabled: Signal<boolean>) {
6163
const issueMessage = `Data Connect Emulator: ${issue.kind.toString()} - ${issue.message}`;
6264
if (issue.severity === Severity.ALERT) {
6365
vscode.window.showErrorMessage(issueMessage);
6466
} else if (issue.severity === Severity.NOTICE) {
6567
vscode.window.showWarningMessage(issueMessage);
6668
}
6769
emulatorOutputChannel.appendLine(issueMessage);
70+
71+
// special handlings
72+
if (issue.kind === Kind.SQL_CONNECTION) {
73+
isPostgresEnabled.value = false;
74+
}
6875
}
6976

7077
/**

firebase-vscode/src/data-connect/emulator.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export class DataConnectEmulatorController implements vscode.Disposable {
2222

2323
// Notify webviews when the emulator status changes
2424
effect(() => {
25+
if (this.isPostgresEnabled) {
26+
this.emulatorsController.emulatorStatusItem.show();
27+
} else {
28+
this.emulatorsController.emulatorStatusItem.hide();
29+
}
2530
notifyIsConnectedToPostgres(this.isPostgresEnabled.value);
2631
}),
2732

@@ -84,10 +89,9 @@ export class DataConnectEmulatorController implements vscode.Disposable {
8489

8590
// configure the emulator to use the local psql string
8691
const emulatorClient = new DataConnectEmulatorClient();
87-
emulatorClient.configureEmulator({ connectionString: newConnectionString });
88-
8992
this.isPostgresEnabled.value = true;
90-
this.emulatorsController.emulatorStatusItem.show();
93+
94+
emulatorClient.configureEmulator({ connectionString: newConnectionString });
9195
}
9296

9397
dispose() {

firebase-vscode/src/data-connect/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ export function registerFdc(
191191
vscode.commands.executeCommand(
192192
"firebase.dataConnect.executeIntrospection",
193193
);
194-
runEmulatorIssuesStream(configs, emulatorController.getLocalEndpoint().value);
194+
runEmulatorIssuesStream(
195+
configs,
196+
emulatorController.getLocalEndpoint().value,
197+
fdcEmulatorsController.isPostgresEnabled,
198+
);
195199
runDataConnectCompiler(configs, emulatorController.getLocalEndpoint().value);
196200
}
197201
}),

0 commit comments

Comments
 (0)