Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Commit

Permalink
[event-hubs] ensure error stack traces only logged in verbose mode (A…
Browse files Browse the repository at this point in the history
  • Loading branch information
chradek authored and sadasant committed Jun 27, 2020
1 parent 8af5c23 commit c172a2c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 29 deletions.
5 changes: 3 additions & 2 deletions sdk/eventhub/event-hubs/src/connectionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@ export namespace ConnectionContext {
logger.info("Closed the amqp connection '%s' on the client.", this.connectionId);
}
} catch (err) {
err = err instanceof Error ? err : JSON.stringify(err);
const errorDescription =
err instanceof Error ? `${err.name}: ${err.message}` : JSON.stringify(err);
logger.warning(
`An error occurred while closing the connection "${this.connectionId}":\n${err}`
`An error occurred while closing the connection "${this.connectionId}":\n${errorDescription}`
);
logErrorStackTrace(err);
throw err;
Expand Down
6 changes: 3 additions & 3 deletions sdk/eventhub/event-hubs/src/eventHubReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export class EventHubReceiver extends LinkEntity {
this._deleteFromCache();
await this._closeLink(receiverLink);
} catch (err) {
const msg = `[${this._context.connectionId}] An error occurred while closing receiver ${this.name}: ${err}`;
const msg = `[${this._context.connectionId}] An error occurred while closing receiver ${this.name}: ${err?.name}: ${err?.message}`;
logger.warning(msg);
logErrorStackTrace(err);
throw err;
Expand Down Expand Up @@ -590,10 +590,10 @@ export class EventHubReceiver extends LinkEntity {
this.isConnecting = false;
const error = translate(err);
logger.warning(
"[%s] An error occured while creating the receiver '%s': %O",
"[%s] An error occured while creating the receiver '%s': %s",
this._context.connectionId,
this.name,
error
`${error?.name}: ${error?.message}`
);
logErrorStackTrace(err);
throw error;
Expand Down
18 changes: 10 additions & 8 deletions sdk/eventhub/event-hubs/src/eventHubSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class EventHubSender extends LinkEntity {
await this._closeLink(senderLink);
}
} catch (err) {
const msg = `[${this._context.connectionId}] An error occurred while closing sender ${this.name}: ${err}`;
const msg = `[${this._context.connectionId}] An error occurred while closing sender ${this.name}: ${err?.name}: ${err?.message}`;
logger.warning(msg);
logErrorStackTrace(err);
throw err;
Expand Down Expand Up @@ -347,7 +347,9 @@ export class EventHubSender extends LinkEntity {
);
return await this._trySendBatch(encodedBatchMessage, options);
} catch (err) {
logger.warning("An error occurred while sending the batch message %O", err);
logger.warning(
`An error occurred while sending the batch message ${err?.name}: ${err?.message}`
);
logErrorStackTrace(err);
throw err;
}
Expand Down Expand Up @@ -463,10 +465,10 @@ export class EventHubSender extends LinkEntity {
removeListeners();
err = translate(err);
logger.warning(
"[%s] An error occurred while creating the sender %s",
"[%s] An error occurred while creating the sender %s: %s",
this._context.connectionId,
this.name,
err
`${err?.name}: ${err?.message}`
);
logErrorStackTrace(err);
return reject(err);
Expand Down Expand Up @@ -504,9 +506,9 @@ export class EventHubSender extends LinkEntity {
} catch (err) {
err = translate(err.innerError || err);
logger.warning(
"[%s] An error occurred while sending the message",
"[%s] An error occurred while sending the message %s",
this._context.connectionId,
err
`${err?.name}: ${err?.message}`
);
logErrorStackTrace(err);
return reject(err);
Expand Down Expand Up @@ -586,10 +588,10 @@ export class EventHubSender extends LinkEntity {
this.isConnecting = false;
err = translate(err);
logger.warning(
"[%s] An error occurred while creating the sender %s",
"[%s] An error occurred while creating the sender %s: %s",
this._context.connectionId,
this.name,
err
`${err?.name}: ${err?.message}`
);
logErrorStackTrace(err);
throw err;
Expand Down
8 changes: 6 additions & 2 deletions sdk/eventhub/event-hubs/src/eventProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ export class EventProcessor {
try {
await this._startPump(partitionId, abortSignal);
} catch (err) {
logger.warning(`[${this._id}] An error occured within the EventProcessor loop: ${err}`);
logger.warning(
`[${this._id}] An error occured within the EventProcessor loop: ${err?.name}: ${err?.message}`
);
logErrorStackTrace(err);
await this._handleSubscriptionError(err);
} finally {
Expand Down Expand Up @@ -456,7 +458,9 @@ export class EventProcessor {
}
}
} catch (err) {
logger.warning(`[${this._id}] An error occured within the EventProcessor loop: ${err}`);
logger.warning(
`[${this._id}] An error occured within the EventProcessor loop: ${err?.name}: ${err?.message}`
);
logErrorStackTrace(err);
// Protect against the scenario where the user awaits on subscription.close() from inside processError.
await Promise.race([this._handleSubscriptionError(err), cancelLoopPromise]);
Expand Down
22 changes: 13 additions & 9 deletions sdk/eventhub/event-hubs/src/managementClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ export class ManagementClient extends LinkEntity {
code: CanonicalCode.UNKNOWN,
message: error.message
});
logger.warning("An error occurred while getting the hub runtime information: %O", error);
logger.warning(
`An error occurred while getting the hub runtime information: ${error?.name}: ${error?.message}`
);
logErrorStackTrace(error);
throw error;
} finally {
Expand Down Expand Up @@ -271,7 +273,9 @@ export class ManagementClient extends LinkEntity {
code: CanonicalCode.UNKNOWN,
message: error.message
});
logger.warning("An error occurred while getting the partition information: %O", error);
logger.warning(
`An error occurred while getting the partition information: ${error?.name}: ${error?.message}`
);
logErrorStackTrace(error);
throw error;
} finally {
Expand All @@ -297,7 +301,7 @@ export class ManagementClient extends LinkEntity {
logger.info("Successfully closed the management session.");
}
} catch (err) {
const msg = `An error occurred while closing the management session: ${err}`;
const msg = `An error occurred while closing the management session: ${err?.name}: ${err?.message}`;
logger.warning(msg);
logErrorStackTrace(err);
throw new Error(msg);
Expand Down Expand Up @@ -365,9 +369,7 @@ export class ManagementClient extends LinkEntity {
} catch (err) {
err = translate(err);
logger.warning(
"[%s] An error occured while establishing the $management links: %O",
this._context.connectionId,
err
`[${this._context.connectionId}] An error occured while establishing the $management links: ${err?.name}: ${err?.message}`
);
logErrorStackTrace(err);
throw err;
Expand Down Expand Up @@ -474,10 +476,10 @@ export class ManagementClient extends LinkEntity {
err = translate(err);
logger.warning(
"[%s] An error occurred during send on management request-response link with address " +
"'%s': %O",
"'%s': %s",
this._context.connectionId,
this.address,
err
`${err?.name}: ${err?.message}`
);
logErrorStackTrace(err);
reject(err);
Expand All @@ -494,7 +496,9 @@ export class ManagementClient extends LinkEntity {
return (await retry<Message>(config)).body;
} catch (err) {
err = translate(err);
logger.warning("An error occurred while making the request to $management endpoint: %O", err);
logger.warning(
`An error occurred while making the request to $management endpoint: ${err?.name}: ${err?.message}`
);
logErrorStackTrace(err);
throw err;
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventhub/event-hubs/src/partitionPump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class PartitionPump {
}
await this._partitionProcessor.close(reason);
} catch (err) {
logger.warning("An error occurred while closing the receiver.", err);
logger.warning(`An error occurred while closing the receiver: ${err?.name}: ${err?.message}`);
logErrorStackTrace(err);
this._partitionProcessor.processError(err);
throw err;
Expand Down
4 changes: 2 additions & 2 deletions sdk/eventhub/event-hubs/src/receiveHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export class ReceiveHandler {
await this._receiver.close();
} catch (err) {
logger.warning(
"An error occurred while stopping the receiver '%s' with address '%s': %O",
"An error occurred while stopping the receiver '%s' with address '%s': %s",
this._receiver.name,
this._receiver.address,
err
`${err?.name}: ${err?.message}`
);
logErrorStackTrace(err);
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/eventhub/event-hubs/src/util/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function throwErrorIfConnectionClosed(context: ConnectionContext): void {
if (context && context.wasConnectionCloseCalled) {
const errorMessage = "The underlying AMQP connection is closed.";
const error = new Error(errorMessage);
logger.warning(`[${context.connectionId}] %O`, error);
logger.warning(`[${context.connectionId}] ${error.name}: ${error.message}`);
logErrorStackTrace(error);
throw error;
}
Expand All @@ -39,7 +39,7 @@ export function throwTypeErrorIfParameterMissing(
const error = new TypeError(
`${methodName} called without required argument "${parameterName}"`
);
logger.warning(`[${connectionId}] %O`, error);
logger.warning(`[${connectionId}] ${error.name}: ${error.message}`);
logErrorStackTrace(error);
throw error;
}
Expand Down

0 comments on commit c172a2c

Please sign in to comment.