Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make error message even better for missing binding #213

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 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,13 @@ 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()}".`
ejizba marked this conversation as resolved.
Show resolved Hide resolved
);
}
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".'
);
});
});
});
Loading