Skip to content

Commit

Permalink
Merge pull request #46 from stormpath/fix-load-file-config-strategy
Browse files Browse the repository at this point in the history
Fix LoadFileConfigStrategy issue with expanded path not being used
  • Loading branch information
Timothy E. Johansson committed Apr 5, 2016
2 parents 15202a3 + d614909 commit 0035ae3
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/strategy/LoadFileConfigStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,40 @@ LoadFileConfigStrategy.prototype.process = function (config, callback) {
var outerScope = this;

var mustExist = this.mustExist;
var filePath = expandHomeDir(this.filePath);
var originalFilePath = this.filePath;
var expandedFilePath = expandHomeDir(originalFilePath);

// In case we don't have a home path but specified a '~' in our path...
if (filePath === false) {
if (expandedFilePath === false) {
if (mustExist) {
return callback(new Error("Unable to load '" + this.filePath + "'. Environment home not set."));
return callback(new Error("Unable to load '" + originalFilePath + "'. Environment home not set."));
}
return callback(null, config);
}

var extension = path.extname(filePath).substring(1);
var extension = path.extname(expandedFilePath).substring(1);
var parser = parsers[extension];

if (!parser) {
return callback(new Error("Unable to load file '" + filePath + "'. Extension '" + extension + "' not supported."));
return callback(new Error("Unable to load file '" + originalFilePath + "'. Extension '" + extension + "' not supported."));
}

fs.exists(this.filePath, function (exists) {
fs.exists(expandedFilePath, function (exists) {
if (!exists) {
if (mustExist) {
callback(new Error("Config file '" + filePath + "' doesn't exist."));
callback(new Error("Config file '" + originalFilePath + "' doesn't exist."));
} else {
callback(null, config);
}
} else {
fs.readFile(filePath, { encoding: outerScope.encoding }, function (err, result) {
fs.readFile(expandedFilePath, { encoding: outerScope.encoding }, function (err, result) {
if (err) {
return callback(err);
}

parser(result, function (err, data) {
if (err) {
return callback(new Error("Error parsing file '" + filePath + "'.\nDetails: " + err));
return callback(new Error("Error parsing file '" + expandedFilePath + "'.\nDetails: " + err));
}

if (data) {
Expand Down

0 comments on commit 0035ae3

Please sign in to comment.