Skip to content

Commit f1e774f

Browse files
authored
[Service Bus] Linting error fixes (Azure#13935)
1 parent 91c1788 commit f1e774f

30 files changed

+277
-153
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"plugins": ["@azure/azure-sdk"],
3+
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"],
4+
"ignorePatterns": ["test/perf/track-1", "test/perf-js-libs", "test/stress"]
5+
}

sdk/servicebus/service-bus/review/service-bus.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export interface GetMessageIteratorOptions extends OperationOptionsBase {
140140
}
141141

142142
// @public
143-
export function isServiceBusError(err: any): err is ServiceBusError;
143+
export function isServiceBusError(err: unknown): err is ServiceBusError;
144144

145145
// @public
146146
export interface MessageHandlers {

sdk/servicebus/service-bus/src/connectionContext.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ export namespace ConnectionContext {
432432
// ...What to do for sessions (connectionContext.messageSessions) ??
433433
}
434434

435-
await refreshConnection(connectionContext);
435+
await refreshConnection();
436436
waitForConnectionRefreshResolve();
437437
waitForConnectionRefreshPromise = undefined;
438438
// The connection should always be brought back up if the sdk did not call connection.close()
@@ -494,10 +494,10 @@ export namespace ConnectionContext {
494494
}
495495
};
496496

497-
async function refreshConnection(connectionContext: ConnectionContext): Promise<void> {
497+
async function refreshConnection(): Promise<void> {
498498
const originalConnectionId = connectionContext.connectionId;
499499
try {
500-
await cleanConnectionContext(connectionContext);
500+
await cleanConnectionContext();
501501
} catch (err) {
502502
logger.logError(
503503
err,
@@ -520,7 +520,7 @@ export namespace ConnectionContext {
520520
connection.on(ConnectionEvents.error, error);
521521
}
522522

523-
async function cleanConnectionContext(connectionContext: ConnectionContext) {
523+
async function cleanConnectionContext() {
524524
// Remove listeners from the connection object.
525525
connectionContext.connection.removeListener(
526526
ConnectionEvents.connectionOpen,

sdk/servicebus/service-bus/src/core/batchingReceiver.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ export class BatchingReceiver extends MessageReceiver {
5050
onSessionError: (context) => {
5151
lastError = context?.session?.error;
5252
},
53-
// ignored for now - the next call will just fail so they'll get an appropriate error from somewhere else.
54-
onClose: async () => {},
55-
onSessionClose: async () => {},
56-
// we don't add credits initially so we don't need to worry about handling any messages.
57-
onMessage: async () => {}
53+
onClose: async () => {
54+
/** Nothing to do here - the next call will just fail so they'll get an appropriate error from somewhere else. */
55+
},
56+
onSessionClose: async () => {
57+
/** Nothing to do here - the next call will just fail so they'll get an appropriate error from somewhere else. */
58+
},
59+
onMessage: async () => {
60+
/** Nothing to do here - we don't add credits initially so we don't need to worry about handling any messages.*/
61+
}
5862
});
5963

6064
await this._init(rcvrOptions, abortSignal);

sdk/servicebus/service-bus/src/core/managementClient.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { AbortSignalLike } from "@azure/abort-controller";
4949
import { ReceiveMode } from "../models";
5050
import { translateServiceBusError } from "../serviceBusError";
5151
import { defaultDataTransformer } from "../dataTransformer";
52+
import { isDefined, isObjectWithProperties } from "../util/typeGuards";
5253

5354
/**
5455
* @internal
@@ -248,16 +249,17 @@ export class ManagementClient extends LinkEntity<RequestResponseLink> {
248249
abortSignal
249250
);
250251
} catch (err) {
251-
err = translateServiceBusError(err);
252+
const translatedError = translateServiceBusError(err);
252253
managementClientLogger.logError(
253-
err,
254+
translatedError,
254255
`${this.logPrefix} An error occurred while establishing the $management links`
255256
);
256-
throw err;
257+
throw translatedError;
257258
}
258259
}
259260

260261
protected async createRheaLink(
262+
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
261263
options: RequestResponseLinkOptions
262264
): Promise<RequestResponseLink> {
263265
const rheaLink = await RequestResponseLink.create(
@@ -294,13 +296,13 @@ export class ManagementClient extends LinkEntity<RequestResponseLink> {
294296
internalLogger: ServiceBusLogger,
295297
sendRequestOptions: SendManagementRequestOptions = {}
296298
): Promise<RheaMessage> {
297-
if (request.message_id == undefined) {
299+
if (request.message_id === undefined) {
298300
request.message_id = generate_uuid();
299301
}
300302
const retryTimeoutInMs =
301303
sendRequestOptions.timeoutInMs ?? Constants.defaultOperationTimeoutInMs;
302304
const initOperationStartTime = Date.now();
303-
const actionAfterTimeout = (reject: (reason?: any) => void) => {
305+
const actionAfterTimeout = (reject: (reason?: any) => void): void => {
304306
const desc: string = `The request with message_id "${request.message_id}" timed out. Please try again later.`;
305307
const e: Error = {
306308
name: "OperationTimeoutError",
@@ -333,16 +335,14 @@ export class ManagementClient extends LinkEntity<RequestResponseLink> {
333335
if (!request.message_id) request.message_id = generate_uuid();
334336
return await this.link!.sendRequest(request, sendRequestOptions);
335337
} catch (err) {
336-
err = translateServiceBusError(err);
338+
const translatedError = translateServiceBusError(err);
337339
internalLogger.logError(
338-
err,
339-
"%s An error occurred during send on management request-response link with address " +
340-
"'%s': %O",
340+
translatedError,
341+
"%s An error occurred during send on management request-response link with address '%s'",
341342
this.logPrefix,
342-
this.address,
343-
err
343+
this.address
344344
);
345-
throw err;
345+
throw translatedError;
346346
}
347347
}
348348

@@ -463,7 +463,7 @@ export class ManagementClient extends LinkEntity<RequestResponseLink> {
463463
Buffer.from(fromSequenceNumber.toBytesBE())
464464
);
465465
messageBody[Constants.messageCount] = types.wrap_int(maxMessageCount!);
466-
if (sessionId != undefined) {
466+
if (isDefined(sessionId)) {
467467
messageBody[Constants.sessionIdMapKey] = sessionId;
468468
}
469469
const request: RheaMessage = {
@@ -525,6 +525,7 @@ export class ManagementClient extends LinkEntity<RequestResponseLink> {
525525
* @param options - Options that can be set while sending the request.
526526
* @returns New lock token expiry date and time in UTC format.
527527
*/
528+
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
528529
async renewLock(lockToken: string, options?: SendManagementRequestOptions): Promise<Date> {
529530
throwErrorIfConnectionClosed(this._context);
530531
if (!options) options = {};
@@ -945,7 +946,7 @@ export class ManagementClient extends LinkEntity<RequestResponseLink> {
945946
*/
946947
async setSessionState(
947948
sessionId: string,
948-
state: any,
949+
state: unknown,
949950
options?: OperationOptionsBase & SendManagementRequestOptions
950951
): Promise<void> {
951952
throwErrorIfConnectionClosed(this._context);
@@ -1255,7 +1256,9 @@ export class ManagementClient extends LinkEntity<RequestResponseLink> {
12551256
if (
12561257
typeof filter !== "boolean" &&
12571258
typeof filter !== "string" &&
1258-
!correlationProperties.some((validProperty) => filter.hasOwnProperty(validProperty))
1259+
!correlationProperties.some((validProperty) =>
1260+
isObjectWithProperties(filter, [validProperty])
1261+
)
12591262
) {
12601263
throw new TypeError(
12611264
`The parameter "filter" should be either a boolean, string or implement the CorrelationRuleFilter interface.`

sdk/servicebus/service-bus/src/core/messageReceiver.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,20 @@ export abstract class MessageReceiver extends LinkEntity<Receiver> {
191191
// Thus make sure that the receiver is present in the client cache.
192192
this._context.messageReceivers[this.name] = this as any;
193193
} catch (err) {
194-
err = translateServiceBusError(err);
195-
logger.logError(err, "%s An error occured while creating the receiver", this.logPrefix);
194+
const translatedError = translateServiceBusError(err);
195+
logger.logError(
196+
translatedError,
197+
"%s An error occured while creating the receiver",
198+
this.logPrefix
199+
);
196200

197201
// Fix the unhelpful error messages for the OperationTimeoutError that comes from `rhea-promise`.
198-
if ((err as MessagingError).code === "OperationTimeoutError") {
199-
err.message = "Failed to create a receiver within allocated time and retry attempts.";
202+
if ((translatedError as MessagingError).code === "OperationTimeoutError") {
203+
translatedError.message =
204+
"Failed to create a receiver within allocated time and retry attempts.";
200205
}
201206

202-
throw err;
207+
throw translatedError;
203208
}
204209
}
205210

sdk/servicebus/service-bus/src/core/messageSender.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { OperationOptionsBase } from "../modelsToBeSharedWithEventHubs";
3737
import { AbortSignalLike } from "@azure/abort-controller";
3838
import { translateServiceBusError } from "../serviceBusError";
3939
import { defaultDataTransformer } from "../dataTransformer";
40+
import { isDefined } from "../util/typeGuards";
4041

4142
/**
4243
* @internal
@@ -169,10 +170,9 @@ export class MessageSender extends LinkEntity<AwaitableSender> {
169170
options: OperationOptionsBase | undefined
170171
): Promise<void> {
171172
const abortSignal = options?.abortSignal;
172-
const timeoutInMs =
173-
this._retryOptions.timeoutInMs == undefined
174-
? Constants.defaultOperationTimeoutInMs
175-
: this._retryOptions.timeoutInMs;
173+
const timeoutInMs = !isDefined(this._retryOptions.timeoutInMs)
174+
? Constants.defaultOperationTimeoutInMs
175+
: this._retryOptions.timeoutInMs;
176176

177177
const sendEventPromise = async (): Promise<void> => {
178178
const initStartTime = Date.now();
@@ -188,14 +188,14 @@ export class MessageSender extends LinkEntity<AwaitableSender> {
188188
`to operation timeout.`
189189
});
190190
} catch (err) {
191-
err = translateServiceBusError(err);
191+
const translatedError = translateServiceBusError(err);
192192
logger.logError(
193-
err,
193+
translatedError,
194194
"%s An error occurred while creating the sender",
195195
this.logPrefix,
196196
this.name
197197
);
198-
throw err;
198+
throw translatedError;
199199
}
200200
}
201201

@@ -271,9 +271,12 @@ export class MessageSender extends LinkEntity<AwaitableSender> {
271271
delivery.id
272272
);
273273
} catch (error) {
274-
error = translateServiceBusError(error.innerError || error);
275-
logger.logError(error, `${this.logPrefix} An error occurred while sending the message`);
276-
throw error;
274+
const translatedError = translateServiceBusError(error.innerError || error);
275+
logger.logError(
276+
translatedError,
277+
`${this.logPrefix} An error occurred while sending the message`
278+
);
279+
throw translatedError;
277280
}
278281
};
279282
const config: RetryConfig<void> = {
@@ -306,13 +309,17 @@ export class MessageSender extends LinkEntity<AwaitableSender> {
306309
}
307310
await this.initLink(options, abortSignal);
308311
} catch (err) {
309-
err = translateServiceBusError(err);
310-
logger.logError(err, `${this.logPrefix} An error occurred while creating the sender`);
312+
const translatedError = translateServiceBusError(err);
313+
logger.logError(
314+
translatedError,
315+
`${this.logPrefix} An error occurred while creating the sender`
316+
);
311317
// Fix the unhelpful error messages for the OperationTimeoutError that comes from `rhea-promise`.
312-
if ((err as MessagingError).code === "OperationTimeoutError") {
313-
err.message = "Failed to create a sender within allocated time and retry attempts.";
318+
if ((translatedError as MessagingError).code === "OperationTimeoutError") {
319+
translatedError.message =
320+
"Failed to create a sender within allocated time and retry attempts.";
314321
}
315-
throw err;
322+
throw translatedError;
316323
}
317324
}
318325

sdk/servicebus/service-bus/src/dataTransformer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { message } from "rhea-promise";
55
import isBuffer from "is-buffer";
66
import { Buffer } from "buffer";
77
import { logErrorStackTrace, logger } from "./log";
8+
import { isObjectWithProperties } from "./util/typeGuards";
89

910
/**
1011
* The default data transformer that will be used by the Azure SDK.
@@ -22,7 +23,7 @@ export const defaultDataTransformer = {
2223
* - content: The given AMQP message body as a Buffer.
2324
* - multiple: true | undefined.
2425
*/
25-
encode(body: any): any {
26+
encode(body: unknown): any {
2627
let result: any;
2728
if (isBuffer(body)) {
2829
result = message.data_section(body);
@@ -55,10 +56,10 @@ export const defaultDataTransformer = {
5556
* @param body - The AMQP message body
5657
* @returns decoded body or the given body as-is.
5758
*/
58-
decode(body: any): any {
59+
decode(body: unknown): any {
5960
let processedBody: any = body;
6061
try {
61-
if (body.content && isBuffer(body.content)) {
62+
if (isObjectWithProperties(body, ["content"]) && isBuffer(body.content)) {
6263
// This indicates that we are getting the AMQP described type. Let us try decoding it.
6364
processedBody = body.content;
6465
}

sdk/servicebus/service-bus/src/log.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { AzureLogger, createClientLogger } from "@azure/logger";
55
import { AmqpError } from "rhea-promise";
6+
import { isObjectWithProperties } from "./util/typeGuards";
67

78
/**
89
* The `@azure/logger` configuration for this package.
@@ -52,8 +53,8 @@ export const managementClientLogger = createServiceBusLogger("service-bus:manage
5253
* @param error - Error containing a stack trace.
5354
* @internal
5455
*/
55-
export function logErrorStackTrace(_logger: AzureLogger, error: any): void {
56-
if (error && error.stack) {
56+
export function logErrorStackTrace(_logger: AzureLogger, error: unknown): void {
57+
if (isObjectWithProperties(error, ["stack"]) && error.stack) {
5758
_logger.verbose(error.stack);
5859
}
5960
}
@@ -78,7 +79,7 @@ export interface ServiceBusLogger extends AzureLogger {
7879
* Creates an AzureLogger with any additional methods for standardized logging (for example, with errors)
7980
* @internal
8081
*/
81-
export function createServiceBusLogger(namespace: string) {
82+
export function createServiceBusLogger(namespace: string): ServiceBusLogger {
8283
const _logger = createClientLogger(namespace) as ServiceBusLogger;
8384

8485
_logger["logError"] = (err: Error | AmqpError | undefined, ...args: any[]): void => {

sdk/servicebus/service-bus/src/receivers/receiver.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ import { createProcessingSpan } from "../diagnostics/instrumentServiceBusMessage
4343
import { receiverLogger as logger } from "../log";
4444
import { translateServiceBusError } from "../serviceBusError";
4545

46+
/**
47+
* The default time to wait for messages _after_ the first message
48+
* has been received.
49+
*
50+
* This timeout only applies to receiveMessages()
51+
*
52+
* @internal
53+
*/
54+
export const defaultMaxTimeAfterFirstMessageForBatchingMs = 1000;
55+
4656
/**
4757
* A receiver that does not handle sessions.
4858
*/
@@ -745,13 +755,3 @@ export class ServiceBusReceiverImpl implements ServiceBusReceiver {
745755
return;
746756
}
747757
}
748-
749-
/**
750-
* The default time to wait for messages _after_ the first message
751-
* has been received.
752-
*
753-
* This timeout only applies to receiveMessages()
754-
*
755-
* @internal
756-
*/
757-
export const defaultMaxTimeAfterFirstMessageForBatchingMs = 1000;

0 commit comments

Comments
 (0)