Skip to content

Commit

Permalink
Fix toolkit crashing when config doesn't parse (#7889)
Browse files Browse the repository at this point in the history
* Fix toolkit crashing when config doesn't parse

* changelog

---------

Co-authored-by: joehan <[email protected]>
  • Loading branch information
hlshen and joehan authored Nov 12, 2024
1 parent 81dca8f commit a02e52f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions firebase-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## NEXT

- [Fixed] Fixed an issue where the toolkit wouldn't start with misconfigured configs

## 0.10.7

- Updated internal firebase-tools dependency to 13.24.2
Expand Down
3 changes: 3 additions & 0 deletions firebase-vscode/src/data-connect/toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DataConnectEmulatorArgs } from "../emulator/dataconnectEmulator";
import { Config } from "../config";
import { RC } from "../rc";
import { findOpenPort } from "../utils/port_utils";
import { pluginLogger } from "../logger-wrapper";

const DEFAULT_PORT = 50001;
/** FDC-specific emulator logic; Toolkit and emulator */
Expand Down Expand Up @@ -46,10 +47,12 @@ export class DataConnectToolkit implements vscode.Disposable {
enable_output_generated_sdk: true,
enable_output_schema_extensions: true,
};
pluginLogger.info(`Starting Data Connect toolkit on port ${port}`);
return DataConnectToolkitController.start(toolkitArgs);
}

async stopFDCToolkit() {
pluginLogger.info(`Stopping Data Connect toolkit`);
return DataConnectToolkitController.stop();
}

Expand Down
1 change: 1 addition & 0 deletions src/dataconnect/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export async function load(
config: Config,
sourceDirectory: string,
): Promise<ServiceInfo> {
// TODO: better error handling when config read fails
const resolvedDir = config.path(sourceDirectory);
const dataConnectYaml = await fileUtils.readDataConnectYaml(resolvedDir);
const serviceName = `projects/${projectId}/locations/${dataConnectYaml.location}/services/${dataConnectYaml.serviceId}`;
Expand Down
6 changes: 3 additions & 3 deletions src/emulator/dataconnectEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ export class DataConnectEmulator implements EmulatorInstance {
this.logger.log("DEBUG", `'fdc build' failed with error: ${err.message}`);
}

const info = await load(this.args.projectId, this.args.config, this.args.configDir);
const dbId = info.dataConnectYaml.schema.datasource.postgresql?.database || "postgres";
const serviceId = info.dataConnectYaml.serviceId;
await start(Emulators.DATACONNECT, {
auto_download: this.args.auto_download,
listen: listenSpecsToString(this.args.listen),
Expand All @@ -92,6 +89,9 @@ export class DataConnectEmulator implements EmulatorInstance {
});
this.usingExistingEmulator = false;
if (this.args.autoconnectToPostgres) {
const info = await load(this.args.projectId, this.args.config, this.args.configDir);
const dbId = info.dataConnectYaml.schema.datasource.postgresql?.database || "postgres";
const serviceId = info.dataConnectYaml.serviceId;
const pgPort = this.args.postgresListen?.[0].port;
const pgHost = this.args.postgresListen?.[0].address;
let connStr = dataConnectLocalConnString();
Expand Down

0 comments on commit a02e52f

Please sign in to comment.