Skip to content

Commit 3a929bc

Browse files
Jacques GermishuysNikaple
authored andcommitted
fix: do not attempt substitution if the loader failed
1 parent 02d754e commit 3a929bc

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/loader/file-loader.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ export const fileLoader = (
100100
searchPlaces,
101101
...options,
102102
loaders,
103-
transform: (result: Record<string, any>) => {
104-
if (options.ignoreEnvironmentVariableSubstitution ?? true) {
103+
transform: (result: Record<string, any> | null) => {
104+
if (
105+
!result ||
106+
(options.ignoreEnvironmentVariableSubstitution ?? true)
107+
) {
105108
return result;
106109
}
107110

tests/e2e/yaml-file-substitutions.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,18 @@ describe('Environment variable substitutions error cases', () => {
225225
);
226226
});
227227

228+
it('should not attempt substitution if the loader failed', async () => {
229+
expect(() =>
230+
AppModule.withYamlSubstitution(
231+
{
232+
ignoreEnvironmentVariableSubstitution: true,
233+
},
234+
ConfigWithAlias,
235+
['.env-missing.yaml'],
236+
),
237+
).toThrowError(`Failed to find configuration file.`);
238+
});
239+
228240
it('array primitives substitution', async () => {
229241
expect(() =>
230242
AppModule.withYamlSubstitution(

tests/src/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export type TestYamlFile =
4949
| '.env-reference-object.sub.yaml'
5050
| '.env-reference-array-of-primitives.sub.yaml'
5151
| '.env-advanced-backward-reference.sub.yaml'
52-
| '.env-with-default.sub.yaml';
52+
| '.env-with-default.sub.yaml'
53+
| '.env-missing.yaml';
5354

5455
@Module({})
5556
export class AppModule {

0 commit comments

Comments
 (0)