From 579bb5fad774a7f8a7790a221bfedfe087a82077 Mon Sep 17 00:00:00 2001 From: Aaron Feledy Date: Tue, 24 Feb 2026 22:56:38 -0600 Subject: [PATCH] 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. Backport of lando/core#440 Fixes lando/core#439 --- CHANGELOG.md | 2 ++ lib/cli.js | 2 +- lib/lando.js | 2 +- utils/load-config-files.js | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 269c404..0bb5845 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }}) +* Fixed crash when `config.yml` is empty instead of containing `{}` [lando/core#439](https://github.com/lando/core/issues/439) + ## v4.0.0-unstable.8 - [December 9, 2025](https://github.com/lando/core-next/releases/tag/v4.0.0-unstable.8) * Updated to prep for `bunification` part 2 diff --git a/lib/cli.js b/lib/cli.js index 91af821..a37eccb 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -558,7 +558,7 @@ module.exports = class Cli { const Yaml = require(`../lib/yaml`); const yaml = new Yaml(); const configFile = path.join(this.defaultConfig().userConfRoot, 'config.yml'); - const config = (fs.existsSync(configFile)) ? yaml.load(configFile) : {}; + const config = (fs.existsSync(configFile)) ? yaml.load(configFile) || {} : {}; const file = yaml.dump(configFile, _.assign({}, config, data)); return yaml.load(file); } diff --git a/lib/lando.js b/lib/lando.js index 496dadd..3403e5c 100644 --- a/lib/lando.js +++ b/lib/lando.js @@ -465,7 +465,7 @@ module.exports = class Lando { } // Load the config and augment so we can get an App - const config = lmerge({}, ..._.map(landoFiles, file => yaml.load(file))); + const config = lmerge({}, ..._.map(landoFiles, file => yaml.load(file) || {})); this.log.info('loading app %s from config files', config.name, landoFiles); // Return us some app! const App = require('./app'); diff --git a/utils/load-config-files.js b/utils/load-config-files.js index 53f0ef6..923291d 100644 --- a/utils/load-config-files.js +++ b/utils/load-config-files.js @@ -52,7 +52,7 @@ module.exports = files => _(files) .filter(source => fs.existsSync(source) || fs.existsSync(source.file)) // If the file is just a string lets map it to an object .map(source => { - return _.isString(source) ? {file: source, data: yaml.load(fs.readFileSync(source))} : source; + return _.isString(source) ? {file: source, data: yaml.load(fs.readFileSync(source)) || {}} : source; }) // Add on the root directory for mapping purposes .map(source => _.merge({}, source, {root: path.dirname(source.file)}))