Skip to content

Commit 5c2666c

Browse files
committed
fix: handle empty YAML config files gracefully
When a YAML file (e.g. ~/.lando/config.yml) is completely empty, yaml.load() returns undefined instead of an object. This causes a TypeError when accessing properties like pluginDirs. Default to an empty object when yaml.load() returns a falsy value across all config loading paths. Fixes #439
1 parent 3cb68fb commit 5c2666c

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})
22

3+
* Fixed crash when `config.yml` is empty instead of containing `{}` [#439](https://github.com/lando/core/issues/439)
4+
35
## v3.26.2 - [December 17, 2025](https://github.com/lando/core/releases/tag/v3.26.2)
46

57
* Updated to use new Lando Alliance Apple Developer certificates

lib/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ module.exports = class Cli {
558558
const Yaml = require(`../lib/yaml`);
559559
const yaml = new Yaml();
560560
const configFile = path.join(this.defaultConfig().userConfRoot, 'config.yml');
561-
const config = (fs.existsSync(configFile)) ? yaml.load(configFile) : {};
561+
const config = (fs.existsSync(configFile)) ? yaml.load(configFile) || {} : {};
562562
const file = yaml.dump(configFile, _.assign({}, config, data));
563563
return yaml.load(file);
564564
}

lib/lando.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ module.exports = class Lando {
465465
}
466466

467467
// Load the config and augment so we can get an App
468-
const config = lmerge({}, ..._.map(landoFiles, file => yaml.load(file)));
468+
const config = lmerge({}, ..._.map(landoFiles, file => yaml.load(file) || {}));
469469
this.log.info('loading app %s from config files', config.name, landoFiles);
470470
// Return us some app!
471471
const App = require('./app');

utils/load-config-files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = files => _(files)
5252
.filter(source => fs.existsSync(source) || fs.existsSync(source.file))
5353
// If the file is just a string lets map it to an object
5454
.map(source => {
55-
return _.isString(source) ? {file: source, data: yaml.load(fs.readFileSync(source))} : source;
55+
return _.isString(source) ? {file: source, data: yaml.load(fs.readFileSync(source)) || {}} : source;
5656
})
5757
// Add on the root directory for mapping purposes
5858
.map(source => _.merge({}, source, {root: path.dirname(source.file)}))

0 commit comments

Comments
 (0)