Skip to content

Commit

Permalink
SNOW-856233 easy logging - not fail on directory search error (#680)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-knozderko authored Oct 31, 2023
1 parent f49e3ef commit 8bfb622
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/configuration/client_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const os = require('os');
const path = require('path');
const fs = require('fs');
const {isString} = require('../util');
const Logger = require('../logger');
const clientConfigFileName = 'sf_client_config.json';

const Levels = Object.freeze({
Expand Down Expand Up @@ -142,9 +143,9 @@ function ConfigurationUtil(fsPromisesModule, processModule) {
function findConfig (filePathFromConnectionString) {
return verifyNotEmpty(filePathFromConnectionString)
.then((filePath) => filePath ?? getFilePathFromEnvironmentVariable())
.then((filePath) => filePath ?? searchForConfigInDictionary('.'))
.then((filePath) => filePath ?? searchForConfigInDictionary(os.homedir()))
.then((filePath) => filePath ?? searchForConfigInDictionary(os.tmpdir()));
.then((filePath) => filePath ?? searchForConfigInDictionary(() => '.', 'driver'))
.then((filePath) => filePath ?? searchForConfigInDictionary(() => os.homedir(), 'home'))
.then((filePath) => filePath ?? searchForConfigInDictionary(() => os.tmpdir(), 'temp'));
}

async function verifyNotEmpty (filePath) {
Expand All @@ -155,9 +156,15 @@ function ConfigurationUtil(fsPromisesModule, processModule) {
return verifyNotEmpty(process.env.SF_CLIENT_CONFIG_FILE);
}

async function searchForConfigInDictionary (dictionary) {
const filePath = path.join(dictionary, clientConfigFileName);
return onlyIfFileExists(filePath);
async function searchForConfigInDictionary (directoryProvider, directoryDescription) {
try {
const directory = directoryProvider();
const filePath = path.join(directory, clientConfigFileName);
return onlyIfFileExists(filePath);
} catch (e) {
Logger.getInstance().error('Error while searching for the client config in %s directory: %s', directoryDescription, e);
return null;
}
}

async function onlyIfFileExists (filePath) {
Expand Down

0 comments on commit 8bfb622

Please sign in to comment.