Skip to content

Commit

Permalink
Undefined environment variables should be empty strings (#550)
Browse files Browse the repository at this point in the history
This PR fixes #549
  • Loading branch information
qianl15 authored Jul 19, 2024
1 parent 993dfad commit 3b2e29a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/dbos-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ export class DBOSExecutor implements DBOSExecutorContext {
// Set configured environment variables
if (config.env) {
for (const [key, value] of Object.entries(config.env)) {
process.env[key] = value;
if (typeof value === "string") {
process.env[key] = value;
} else {
console.warn(`Invalid value type for environment variable ${key}: ${typeof value}`);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/dbos-runtime/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface ConfigFile {
export function substituteEnvVars(content: string): string {
const regex = /\${([^}]+)}/g; // Regex to match ${VAR_NAME} style placeholders
return content.replace(regex, (_, g1: string) => {
return process.env[g1] || ""; // If the env variable is not set, return an empty string.
return process.env[g1] || '""'; // If the env variable is not set, return an empty string.
});
}

Expand Down
2 changes: 2 additions & 0 deletions tests/dbos-runtime/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,14 @@ describe("dbos-config", () => {
app_db_name: 'some DB'
env:
FOOFOO: barbar
RANDENV: \${SOMERANDOMENV}
`;
jest.restoreAllMocks();
jest.spyOn(utils, "readFileSync").mockReturnValue(localMockDBOSConfigYamlString);
const [dbosConfig, _dbosRuntimeConfig]: [DBOSConfig, DBOSRuntimeConfig] = parseConfigFile(mockCLIOptions);
const dbosExec = new DBOSExecutor(dbosConfig);
expect(process.env.FOOFOO).toBe("barbar");
expect(process.env.RANDENV).toBe(""); // Empty string
// We didn't init, so do some manual cleanup only
clearInterval(dbosExec.flushBufferID);
await dbosExec.telemetryCollector.destroy();
Expand Down

0 comments on commit 3b2e29a

Please sign in to comment.