Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-856233 easy logging - not fail on directory search error #680

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading