Skip to content

Commit 919ab3b

Browse files
committed
getConfig: cleanup new optional property names
1 parent fcc9a4a commit 919ab3b

File tree

8 files changed

+26
-25
lines changed

8 files changed

+26
-25
lines changed

client/modules/IDE/actions/project.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import {
1515
} from './ide';
1616
import { clearState, saveState } from '../../../persistState';
1717

18-
const ROOT_URL = getConfig('API_URL', { failOnNotFound: true });
18+
const ROOT_URL = getConfig('API_URL', { throwErrorIfNotFound: true });
1919
const S3_BUCKET_URL_BASE = getConfig('S3_BUCKET_URL_BASE', {
20-
failOnNotFound: true
20+
throwErrorIfNotFound: true
2121
});
22-
const S3_BUCKET = getConfig('S3_BUCKET', { failOnNotFound: true });
22+
const S3_BUCKET = getConfig('S3_BUCKET', { throwErrorIfNotFound: true });
2323

2424
export function setProject(project) {
2525
return {

client/modules/IDE/components/PreviewFrame.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const Frame = styled.iframe`
1313

1414
function PreviewFrame({ fullView, isOverlayVisible }) {
1515
const iframe = useRef();
16-
const previewUrl = getConfig('PREVIEW_URL', { failOnNotFound: true });
16+
const previewUrl = getConfig('PREVIEW_URL', { throwErrorIfNotFound: true });
1717
useEffect(() => {
1818
const unsubscribe = registerFrame(iframe.current.contentWindow, previewUrl);
1919
return () => {

client/modules/IDE/components/SketchListRowBase.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import MenuItem from '../../../components/Dropdown/MenuItem';
1111
import { formatDateToString } from '../../../utils/formatDate';
1212
import { getConfig } from '../../../utils/getConfig';
1313

14-
const ROOT_URL = getConfig('API_URL', { failOnNotFound: true });
14+
const ROOT_URL = getConfig('API_URL', { throwErrorIfNotFound: true });
1515

1616
const formatDateCell = (date, mobile = false) =>
1717
formatDateToString(date, { showTime: !mobile });

client/modules/Preview/EmbedFrame.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ p5.prototype.registerMethod('afterSetup', p5.prototype.ensureAccessibleCanvas);`
246246
window.objectUrls = ${JSON.stringify(objectUrls)};
247247
window.objectPaths = ${JSON.stringify(objectPaths)};
248248
window.editorOrigin = '${getConfig('EDITOR_URL', {
249-
failOnNotFound: true
249+
throwErrorIfNotFound: true
250250
})}';
251251
`;
252252
addLoopProtect(sketchDoc);

client/modules/Preview/previewIndex.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const App = () => {
2626
const [gridOutput, setGridOutput] = useState(false);
2727
registerFrame(
2828
window.parent,
29-
getConfig('EDITOR_URL', { failOnNotFound: true })
29+
getConfig('EDITOR_URL', { throwErrorIfNotFound: true })
3030
);
3131

3232
function handleMessageEvent(message) {

client/utils/apiClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios, { AxiosInstance } from 'axios';
22
import { getConfig } from './getConfig';
33

4-
const ROOT_URL = getConfig('API_URL', { failOnNotFound: true });
4+
const ROOT_URL = getConfig('API_URL', { throwErrorIfNotFound: true });
55

66
/**
77
* Configures an Axios instance with the correct API URL

client/utils/getConfig.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ describe('utils/getConfig()', () => {
2828

2929
// check returns unhappy path
3030
describe('and when the key does not exist in the env file', () => {
31-
it('warns but does not throw if failOnNotFound is false (default)', () => {
31+
it('warns but does not throw if throwErrorIfNotFound is false (default)', () => {
3232
expect(() => getConfig('CONFIG_TEST_KEY_NAME')).not.toThrow();
3333
});
3434

35-
it('throws an error if failOnNotFound is true', () => {
35+
it('throws an error if throwErrorIfNotFound is true', () => {
3636
process.env.NODE_ENV = 'not_test';
3737
expect(() =>
3838
getConfig('CONFIG_TEST_KEY_NAME', {
39-
failOnNotFound: true,
40-
failInTestEnv: true
39+
throwErrorIfNotFound: true,
40+
throwErrorInTestEnv: true
4141
})
4242
).toThrow();
4343
});
@@ -60,15 +60,15 @@ describe('utils/getConfig()', () => {
6060
global.process.env.CONFIG_TEST_KEY_NAME = '';
6161
});
6262

63-
it('warns but does not throw if failOnNotFound is false (default)', () => {
63+
it('warns but does not throw if throwErrorIfNotFound is false (default)', () => {
6464
expect(() => getConfig('CONFIG_TEST_KEY_NAME')).not.toThrow();
6565
});
6666

67-
it('throws an error if failOnNotFound is true', () => {
67+
it('throws an error if throwErrorIfNotFound is true', () => {
6868
expect(() =>
6969
getConfig('CONFIG_TEST_KEY_NAME', {
70-
failOnNotFound: true,
71-
failInTestEnv: true
70+
throwErrorIfNotFound: true,
71+
throwErrorInTestEnv: true
7272
})
7373
).toThrow();
7474
});

client/utils/getConfig.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,29 @@ function getEnvVar(key: string): string | undefined {
1212
interface GetConfigOptions {
1313
warn?: boolean;
1414
nullishString?: boolean;
15-
failOnNotFound?: boolean;
16-
failInTestEnv?: boolean; // this is only to test getConfig and should never be set to override defaults
15+
throwErrorIfNotFound?: boolean;
16+
throwErrorInTestEnv?: boolean; // this is only to test getConfig and should never be set to override defaults
1717
}
1818

1919
export const isTestEnvironment = getEnvVar('NODE_ENV') === 'test';
2020

2121
const defaultGetConfigOptions: GetConfigOptions = {
2222
warn: !isTestEnvironment,
2323
nullishString: false,
24-
failOnNotFound: false,
25-
failInTestEnv: false
24+
throwErrorIfNotFound: false,
25+
throwErrorInTestEnv: false
2626
};
2727

2828
/**
2929
* Returns a string config value from environment variables.
30-
* Logs a warning or throws an error if the value is missing, if `warn` and `failOnNotFound` are true in options
30+
* Logs a warning or throws an error if the value is missing, if `warn` and `throwErrorIfNotFound` are true in options
3131
*
3232
* @param key - The environment variable key to fetch.
3333
* @param options - Optional settings:
34-
* - `failOnNotFound`: whether to throw an error if the value is missing (default to `false`).
34+
* - `throwErrorIfNotFound`: whether to throw an error if the value is missing (default to `false`).
3535
* - `warn`: whether to warn if the value is missing (default `true` unless in test env).
3636
* - `nullishString`: if true, returns `''` instead of `undefined` when missing.
37+
* - `throwErrorInTestEnv`: this is to test getConfig and should not be overridden (default to `false`).
3738
* @returns String value of the env var, or `''` or `undefined` if missing.
3839
*/
3940
export function getConfig(
@@ -45,7 +46,7 @@ export function getConfig(
4546
}
4647

4748
// override default options with param options
48-
const { warn, nullishString, failOnNotFound, failInTestEnv } = {
49+
const { warn, nullishString, throwErrorIfNotFound, throwErrorInTestEnv } = {
4950
...defaultGetConfigOptions,
5051
...options
5152
};
@@ -59,8 +60,8 @@ export function getConfig(
5960

6061
// error, warn or continue if no value found:
6162
if (
62-
(failOnNotFound && !isTestEnvironment) ||
63-
(failOnNotFound && isTestEnvironment && failInTestEnv) // this is just to enable us to test getConfig's error throwing
63+
(throwErrorIfNotFound && !isTestEnvironment) ||
64+
(throwErrorIfNotFound && isTestEnvironment && throwErrorInTestEnv) // this is just to enable us to test getConfig's error throwing
6465
) {
6566
throw new Error(notFoundMessage);
6667
}

0 commit comments

Comments
 (0)