Skip to content

Commit c2e09e2

Browse files
sophia-bqSophia Chu
andauthored
fix: errors thrown in plugin construction may appear as a missing dependency (#247)
Co-authored-by: Sophia Chu <[email protected]>
1 parent 4fc09b5 commit c2e09e2

File tree

11 files changed

+28
-16
lines changed

11 files changed

+28
-16
lines changed

common/lib/authentication/aws_secrets_manager_plugin_factory.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ export class AwsSecretsManagerPluginFactory implements ConnectionPluginFactory {
2727
const awsSecretsManagerPlugin = await import("./aws_secrets_manager_plugin");
2828
return new awsSecretsManagerPlugin.AwsSecretsManagerPlugin(pluginService, new Map(properties));
2929
} catch (error: any) {
30-
logger.error(error);
31-
throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", "AwsSecretsManagerPlugin"));
30+
if (error.code === "MODULE_NOT_FOUND") {
31+
logger.error(error);
32+
throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", "AwsSecretsManagerPlugin"));
33+
}
34+
throw error;
3235
}
3336
}
3437
}

common/lib/host_info_builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { HostAvailability } from "./host_availability/host_availability";
1919
import { HostInfo } from "./host_info";
2020
import { HostAvailabilityStrategy } from "./host_availability/host_availability_strategy";
2121
import { AwsWrapperError } from "./utils/errors";
22+
import { Messages } from "./utils/messages";
2223

2324
export class HostInfoBuilder {
2425
private host: string;
@@ -99,7 +100,7 @@ export class HostInfoBuilder {
99100

100101
build() {
101102
if (!this.host) {
102-
throw new AwsWrapperError("host parameter must be set");
103+
throw new AwsWrapperError(Messages.get("HostInfo.noHostParameter"));
103104
}
104105
return new HostInfo(
105106
this.host,

common/lib/plugin_manager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class PluginChain<T> {
5454

5555
execute(pluginFunc: PluginFunc<T>): Promise<T> {
5656
if (this.chain === undefined) {
57-
throw new AwsWrapperError(Messages.get("PluginManager.PipelineNone"));
57+
throw new AwsWrapperError(Messages.get("PluginManager.pipelineNone"));
5858
}
5959
return this.chain(pluginFunc, this.targetFunc);
6060
}
@@ -113,7 +113,7 @@ export class PluginManager {
113113

114114
async execute<T>(hostInfo: HostInfo | null, props: Map<string, any>, methodName: string, methodFunc: () => Promise<T>, options: any): Promise<T> {
115115
if (hostInfo == null) {
116-
throw new AwsWrapperError("No host");
116+
throw new AwsWrapperError(Messages.get("HostInfo.noHostParameter"));
117117
}
118118

119119
const telemetryContext = this.telemetryFactory.openTelemetryContext(methodName, TelemetryTraceLevel.NESTED);
@@ -130,7 +130,7 @@ export class PluginManager {
130130

131131
async connect(hostInfo: HostInfo | null, props: Map<string, any>, isInitialConnection: boolean): Promise<ClientWrapper> {
132132
if (hostInfo == null) {
133-
throw new AwsWrapperError("HostInfo was not provided.");
133+
throw new AwsWrapperError(Messages.get("HostInfo.noHostParameter"));
134134
}
135135

136136
const telemetryContext = this.telemetryFactory.openTelemetryContext(PluginManager.CONNECT_METHOD, TelemetryTraceLevel.NESTED);
@@ -150,7 +150,7 @@ export class PluginManager {
150150

151151
async forceConnect(hostInfo: HostInfo | null, props: Map<string, any>, isInitialConnection: boolean): Promise<ClientWrapper> {
152152
if (hostInfo == null) {
153-
throw new AwsWrapperError("HostInfo was not provided.");
153+
throw new AwsWrapperError(Messages.get("HostInfo.noHostParameter"));
154154
}
155155

156156
const telemetryContext = this.telemetryFactory.openTelemetryContext(PluginManager.FORCE_CONNECT_METHOD, TelemetryTraceLevel.NESTED);

common/lib/plugin_service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export class PluginService implements ErrorHandler, HostListProviderService {
390390
}
391391
return changes;
392392
}
393-
throw new AwsWrapperError("HostInfo not found"); // Should not be reached
393+
throw new AwsWrapperError(Messages.get("HostInfo.noHostParameter")); // Should not be reached
394394
}
395395
}
396396

common/lib/plugins/aurora_initial_connection_strategy_plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class AuroraInitialConnectionStrategyPlugin extends AbstractConnectionPlu
113113

114114
async getVerifiedWriterClient<T>(props: Map<string, any>, isInitialConnection: boolean, connectFunc: () => Promise<T>): Promise<any> {
115115
if (!this.hostListProviderService) {
116-
throw new AwsWrapperError("Host list provider service not found."); // should not be reached
116+
throw new AwsWrapperError(Messages.get("HostListProviderService.notFound")); // should not be reached
117117
}
118118
const retryDelayMs = WrapperProperties.OPEN_CONNECTION_RETRY_INTERVAL_MS.get(props);
119119

@@ -177,7 +177,7 @@ export class AuroraInitialConnectionStrategyPlugin extends AbstractConnectionPlu
177177

178178
async getVerifiedReaderClient<T>(props: Map<string, any>, isInitialConnection: boolean, connectFunc: () => Promise<T>): Promise<any> {
179179
if (!this.hostListProviderService) {
180-
throw new AwsWrapperError("Host list provider service not found."); // should not be reached
180+
throw new AwsWrapperError(Messages.get("HostListProviderService.notFound")); // should not be reached
181181
}
182182

183183
const retryDelayMs = WrapperProperties.OPEN_CONNECTION_RETRY_INTERVAL_MS.get(props);

common/lib/plugins/federated_auth/saml_credentials_provider_factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export abstract class SamlCredentialsProviderFactory implements CredentialsProvi
5656

5757
formatIdpEndpoint(idpEndpoint: string): string {
5858
// Only add "https://" if user has passed their idpEndpoint without the URL scheme.
59-
if (!idpEndpoint.startsWith("https://")) {
59+
if (idpEndpoint && !idpEndpoint.startsWith("https://")) {
6060
return `https://${idpEndpoint}`;
6161
}
6262
return idpEndpoint;

common/lib/plugins/stale_dns/stale_dns_plugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { HostInfo } from "../../host_info";
2222
import { HostChangeOptions } from "../../host_change_options";
2323
import { AwsWrapperError } from "../../utils/errors";
2424
import { ClientWrapper } from "../../client_wrapper";
25+
import { Messages } from "../../utils/messages";
2526

2627
export class StaleDnsPlugin extends AbstractConnectionPlugin {
2728
private static readonly subscribedMethods: Set<string> = new Set<string>(["initHostProvider", "connect", "forceConnect", "notifyHostListChanged"]);
@@ -46,7 +47,7 @@ export class StaleDnsPlugin extends AbstractConnectionPlugin {
4647
connectFunc: () => Promise<ClientWrapper>
4748
): Promise<ClientWrapper> {
4849
if (!this.hostListProviderService) {
49-
throw new AwsWrapperError("HostListProviderService not found");
50+
throw new AwsWrapperError(Messages.get("HostListProviderService.notFound"));
5051
}
5152
return await this.staleDnsHelper.getVerifiedConnection(hostInfo.host, isInitialConnection, this.hostListProviderService, properties, connectFunc);
5253
}
@@ -58,7 +59,7 @@ export class StaleDnsPlugin extends AbstractConnectionPlugin {
5859
connectFunc: () => Promise<ClientWrapper>
5960
): Promise<ClientWrapper> {
6061
if (!this.hostListProviderService) {
61-
throw new AwsWrapperError("HostListProviderService not found");
62+
throw new AwsWrapperError(Messages.get("HostListProviderService.notFound"));
6263
}
6364
return await this.staleDnsHelper.getVerifiedConnection(hostInfo.host, isInitialConnection, this.hostListProviderService, properties, connectFunc);
6465
}

common/lib/utils/connection_url_parser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { HostRole } from "../host_role";
1919
import { HostInfoBuilder } from "../host_info_builder";
2020
import { RdsUrlType } from "./rds_url_type";
2121
import { HostInfo } from "../host_info";
22+
import { AwsWrapperError } from "../utils/errors";
23+
import { Messages } from "./messages";
2224

2325
export abstract class ConnectionUrlParser {
2426
protected static readonly HOST_SEPARATOR = ",";
@@ -70,6 +72,9 @@ export abstract class ConnectionUrlParser {
7072
fallbackPort: number,
7173
builderFunc: () => HostInfoBuilder
7274
): HostInfo[] {
75+
if (!initialConnection) {
76+
throw new AwsWrapperError(Messages.get("HostInfo.noHostParameter"));
77+
}
7378
const hostsList: HostInfo[] = [];
7479
const hosts: string[] = this.getHostPortPairsFromUrl(initialConnection);
7580
hosts.forEach((pair, i) => {

common/lib/utils/locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"PluginManager.unknownPluginCode": "Unknown plugin code: '%s'",
3-
"PluginManager.PipelineNone": "A pipeline was requested but the created pipeline evaluated to None.",
3+
"PluginManager.pipelineNone": "A pipeline was requested but the created pipeline evaluated to undefined.",
44
"PluginManager.unableToRetrievePlugin": "Unable to retrieve plugin instance.",
55
"ConnectionProvider.unsupportedHostSelectorStrategy": "Unsupported host selection strategy '%s' specified for this connection provider '%s'. Please visit the documentation for all supported strategies.",
66
"ConnectionProvider.unsupportedHostInfoSelectorStrategy": "Unsupported host selection strategy '%s' specified for this connection provider '%s'. Please visit the documentation for all supported strategies.",
@@ -12,6 +12,8 @@
1212
"DefaultConnectionPlugin.unknownRoleRequested": "A HostInfo with a role of HostRole.UNKNOWN was requested via getHostInfoByStrategy. The requested role must be either HostRole.WRITER or HostRole.READER",
1313
"DefaultConnectionPlugin.noHostsAvailable": "The default connection plugin received an empty host list from the plugin service.",
1414
"HostSelector.noHostsMatchingRole": "No hosts were found matching the requested '%s' role.",
15+
"HostListProviderService.notFound": "HostListProviderService not found.",
16+
"HostInfo.noHostParameter": "Host parameter must be set, HostInfo not found or not provided.",
1517
"HostInfo.weightLessThanZero": "A HostInfo object was created with a weight value less than 0.",
1618
"AwsSecretsManagerConnectionPlugin.failedToFetchDbCredentials": "Was not able to either fetch or read the database credentials from AWS Secrets Manager. Ensure the correct secretId and region properties have been provided.",
1719
"AwsSecretsManagerConnectionPlugin.missingRequiredConfigParameter": "Configuration parameter 'secretId' is required.",

mysql/lib/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class AwsMySQLClient extends AwsClient {
5757
return await context.start(async () => {
5858
const hostInfo = this.pluginService.getCurrentHostInfo();
5959
if (hostInfo == null) {
60-
throw new AwsWrapperError("HostInfo was not provided.");
60+
throw new AwsWrapperError(Messages.get("HostInfo.noHostParameter"));
6161
}
6262
const result: ClientWrapper = await this.pluginManager.connect(hostInfo, this.properties, true);
6363
await this.pluginService.setCurrentClient(result, result.hostInfo);

0 commit comments

Comments
 (0)