Skip to content

Commit 949dcdd

Browse files
authored
Fix when missing functionConfig (#175)
1 parent adee356 commit 949dcdd

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

ts/kpt-functions/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts/kpt-functions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kpt-functions",
3-
"version": "0.14.2",
3+
"version": "0.14.3",
44
"description": "KPT functions framework library",
55
"author": "KPT Authors",
66
"license": "Apache-2.0",

ts/kpt-functions/src/types.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,10 @@ export class Configs {
172172
* Throws a FunctionConfigError if functionConfig is undefined OR
173173
* if the kind is not a v1/ConfigMap.
174174
*/
175-
getFunctionConfigMap() {
175+
getFunctionConfigMap(): Map<string, string> | undefined {
176176
const cm = this.getFunctionConfig();
177177
if (cm === undefined) {
178-
throw new FunctionConfigError(
179-
`functionConfig expected, instead undefined`
180-
);
178+
return undefined;
181179
}
182180
if (!isConfigMap(cm)) {
183181
throw new FunctionConfigError(
@@ -204,7 +202,8 @@ export class Configs {
204202
* @key key The key in the 'data' field in the ConfigMap object given as the functionConfig.
205203
*/
206204
getFunctionConfigValue(key: string): string | undefined {
207-
return this.getFunctionConfigMap().get(key);
205+
const cm = this.getFunctionConfigMap();
206+
return cm ? cm.get(key) : cm;
208207
}
209208

210209
/**

ts/kpt-functions/src/types_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ describe('functionConfig', () => {
264264
it('no object', () => {
265265
const configs = new Configs(undefined);
266266
expect(configs.getFunctionConfig()).toBeUndefined();
267-
expect(() => configs.getFunctionConfigMap()).toThrow();
268-
expect(() => configs.getFunctionConfigValue('k3')).toThrow();
267+
expect(configs.getFunctionConfigMap()).toBeUndefined();
268+
expect(configs.getFunctionConfigValue('k3')).toBeUndefined();
269269
expect(() => configs.getFunctionConfigValueOrThrow('k3')).toThrow();
270270
});
271271

0 commit comments

Comments
 (0)