Skip to content

Commit 344e4d5

Browse files
authored
Improve error message for streaming on old host version (#226)
1 parent d488b48 commit 344e4d5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/setup.ts

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

44
import { SetupOptions } from '../types';
55
import { AzFuncSystemError } from './errors';
6+
import { tryGetCoreApiLazy } from './utils/tryGetCoreApiLazy';
67
import { workerSystemLog } from './utils/workerSystemLog';
78

89
let options: SetupOptions = {};
@@ -16,6 +17,16 @@ export function setup(opts: SetupOptions): void {
1617
if (setupLocked) {
1718
throw new AzFuncSystemError("Setup options can't be changed after app startup has finished.");
1819
}
20+
21+
if (opts.enableHttpStream) {
22+
// NOTE: coreApi.log was coincidentally added the same time as http streaming,
23+
// so we can use that to validate the host version instead of messing with semver parsing
24+
const coreApi = tryGetCoreApiLazy();
25+
if (coreApi && !coreApi.log) {
26+
throw new AzFuncSystemError(`HTTP streaming requires Azure Functions Host v4.28 or higher.`);
27+
}
28+
}
29+
1930
options = opts;
2031
workerSystemLog('information', `Setup options: ${JSON.stringify(options)}`);
2132
}

src/utils/workerSystemLog.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { tryGetCoreApiLazy } from './tryGetCoreApiLazy';
88

99
export function workerSystemLog(level: types.LogLevel, ...args: unknown[]): void {
1010
const coreApi = tryGetCoreApiLazy();
11-
if (coreApi) {
11+
// NOTE: coreApi.log doesn't exist on older versions of the worker
12+
if (coreApi && coreApi.log) {
1213
coreApi.log(level, 'system', format(...args));
1314
} else {
1415
fallbackLogHandler(level, ...args);

0 commit comments

Comments
 (0)