Skip to content

Commit

Permalink
Make error message even better for missing binding (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejizba authored Jan 30, 2024
1 parent 6e68b78 commit a94e78c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/InvocationModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { fromRpcTypedData } from './converters/fromRpcTypedData';
import { toCamelCaseValue } from './converters/toCamelCase';
import { toRpcHttp } from './converters/toRpcHttp';
import { toRpcTypedData } from './converters/toRpcTypedData';
import { AzFuncSystemError } from './errors';
import { InvocationContext } from './InvocationContext';
import { isHttpTrigger, isTimerTrigger, isTrigger } from './utils/isTrigger';
import { isDefined, nonNullProp, nonNullValue } from './utils/nonNull';
Expand Down Expand Up @@ -62,7 +63,15 @@ export class InvocationModel implements coreTypes.InvocationModel {
const bindingName = nonNullProp(binding, 'name');
let input: unknown = fromRpcTypedData(binding.data);

const bindingType = nonNullProp(this.#bindings, bindingName).type;
const rpcBinding = this.#bindings[bindingName];
if (!rpcBinding) {
throw new AzFuncSystemError(
`Failed to find binding "${bindingName}" in bindings "${Object.keys(this.#bindings).join(
', '
)}".`
);
}
const bindingType = rpcBinding.type;
if (isTimerTrigger(bindingType)) {
input = toCamelCaseValue(input);
}
Expand Down
31 changes: 31 additions & 0 deletions test/InvocationModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,36 @@ describe('InvocationModel', () => {
const response = await model.getResponse(context, undefined);
expect(response).to.deep.equal({ invocationId: 'testInvocId', outputData: [], returnValue: undefined });
});

// https://github.com/Azure/azure-functions-nodejs-library/issues/210
it('Missing binding', async () => {
const model = new InvocationModel({
invocationId: 'testInvocId',
metadata: {
name: 'testFuncName',
bindings: {
httpTrigger1: {
type: 'httpTrigger',
direction: 'in',
},
$return: {
type: 'http',
direction: 'out',
},
},
},
request: {
inputData: [
{
name: 'httpTriggerMissing',
},
],
},
log: testLog,
});
await expect(model.getArguments()).to.be.rejectedWith(
'Failed to find binding "httpTriggerMissing" in bindings "httpTrigger1, $return".'
);
});
});
});

0 comments on commit a94e78c

Please sign in to comment.