Skip to content

Commit 7e945f3

Browse files
committed
check method before calling external middlewareStack instance
1 parent b9b29cc commit 7e945f3

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

.changeset/few-crews-brake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/middleware-stack": patch
3+
---
4+
5+
check calls to external instances of middlewareStack

packages/middleware-stack/src/MiddlewareStack.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,22 @@ describe("MiddlewareStack", () => {
370370
});
371371
});
372372

373+
it("checks identifyOnResolve calls to external instances due to version mismatching", () => {
374+
const newStack = constructStack<input, output>();
375+
const oldStack = constructStack<input, output>();
376+
377+
delete (oldStack as any).identifyOnResolve;
378+
oldStack.clone = () => oldStack;
379+
oldStack.concat = <S>(stack: S) => oldStack as S;
380+
oldStack.applyToStack = () => void 0;
381+
382+
expect(oldStack.identifyOnResolve).toBeUndefined();
383+
expect(() => {
384+
newStack.concat(oldStack);
385+
newStack.clone();
386+
}).not.toThrow();
387+
});
388+
373389
describe("use", () => {
374390
it("should apply customizations from pluggables", async () => {
375391
const stack = constructStack<input, output>();

packages/middleware-stack/src/MiddlewareStack.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export const constructStack = <Input extends object, Output extends object>(): M
6969
//@ts-ignore
7070
toStack.addRelativeTo(entry.middleware, { ...entry });
7171
});
72-
toStack.identifyOnResolve(stack.identifyOnResolve());
72+
if (typeof toStack.identifyOnResolve === "function") {
73+
toStack.identifyOnResolve(stack.identifyOnResolve());
74+
}
7375
return toStack;
7476
};
7577

@@ -239,7 +241,9 @@ export const constructStack = <Input extends object, Output extends object>(): M
239241
): MiddlewareStack<InputType, OutputType> => {
240242
const cloned = cloneTo(constructStack<InputType, OutputType>());
241243
cloned.use(from);
242-
cloned.identifyOnResolve(identifyOnResolve || cloned.identifyOnResolve() || from.identifyOnResolve());
244+
cloned.identifyOnResolve(
245+
identifyOnResolve || cloned.identifyOnResolve() || (from.identifyOnResolve?.() ?? false)
246+
);
243247
return cloned;
244248
},
245249

0 commit comments

Comments
 (0)