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

Improve error message for streaming on old host version #226

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { SetupOptions } from '../types';
import { AzFuncSystemError } from './errors';
import { tryGetCoreApiLazy } from './utils/tryGetCoreApiLazy';
import { workerSystemLog } from './utils/workerSystemLog';

let options: SetupOptions = {};
Expand All @@ -16,6 +17,16 @@ export function setup(opts: SetupOptions): void {
if (setupLocked) {
throw new AzFuncSystemError("Setup options can't be changed after app startup has finished.");
}

if (opts.enableHttpStream) {
// NOTE: coreApi.log was coincidentally added the same time as http streaming,
// so we can use that to validate the host version instead of messing with semver parsing
const coreApi = tryGetCoreApiLazy();
if (coreApi && !coreApi.log) {
throw new AzFuncSystemError(`HTTP streaming requires Azure Functions Host v4.28 or higher.`);
}
}

options = opts;
workerSystemLog('information', `Setup options: ${JSON.stringify(options)}`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/workerSystemLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { tryGetCoreApiLazy } from './tryGetCoreApiLazy';

export function workerSystemLog(level: types.LogLevel, ...args: unknown[]): void {
const coreApi = tryGetCoreApiLazy();
if (coreApi) {
// NOTE: coreApi.log doesn't exist on older versions of the worker
if (coreApi && coreApi.log) {
coreApi.log(level, 'system', format(...args));
} else {
fallbackLogHandler(level, ...args);
Expand Down
Loading