Skip to content

Commit b3c232f

Browse files
authored
Print a useful error explaining why Runtime Config doesn't work (#930)
* Print a useful error explaining why Runtime Config doesn't work * PR feedback
1 parent 4493e35 commit b3c232f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

spec/v1/config.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ describe('config()', () => {
4747
(config as any).firebaseConfigCache = null;
4848
delete process.env.FIREBASE_CONFIG;
4949
delete process.env.CLOUD_RUNTIME_CONFIG;
50+
delete process.env.K_CONFIGURATION;
51+
});
52+
53+
it('will never load in GCFv2', () => {
54+
const json = JSON.stringify({
55+
foo: 'bar',
56+
firebase: {},
57+
});
58+
readFileSync
59+
.withArgs('/srv/.runtimeconfig.json')
60+
.returns(Buffer.from(json));
61+
62+
process.env.K_CONFIGURATION = 'my-service';
63+
expect(() => config.config()).to.throw(
64+
Error,
65+
/transition to using environment variables/
66+
);
5067
});
5168

5269
it('loads config values from .runtimeconfig.json', () => {

src/v1/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ import * as path from 'path';
2626
import * as firebase from 'firebase-admin';
2727

2828
export function config(): config.Config {
29+
// K_CONFIGURATION is only set in GCFv2
30+
if (process.env.K_CONFIGURATION) {
31+
throw new Error(
32+
'functions.config() is no longer available in Cloud Functions for ' +
33+
'Firebase v2. Please see the latest documentation for information ' +
34+
'on how to transition to using environment variables'
35+
);
36+
}
2937
if (typeof config.singleton === 'undefined') {
3038
init();
3139
}

0 commit comments

Comments
 (0)