Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
schusj committed Aug 9, 2024
1 parent dc9f936 commit 3518fcc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions bin/sql-formatter-cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ class SqlFormatterCli {
return this.parseFile(localConfig);
}

async findConfig(dir = __dirname) {
findConfig(dir = __dirname) {
const filePath = path.join(dir, '.sql-formatter.json');
if (!fs.existsSync(filePath)) {
const parentDir = path.resolve(dir, '..');
if (parentDir === dir) {
return null;
}
return await this.findConfig(parentDir);
return this.findConfig(parentDir);
}

return filePath;
Expand All @@ -131,12 +131,19 @@ class SqlFormatterCli {
}

async readFile(filename) {
return promisify(fs.readFile)(filename, { encoding: 'utf-8' }).catch(e => {
try {


return promisify(fs.readFile)(filename, { encoding: 'utf-8' })
} catch (e) {


this.exitWhenIOError(e, filename);
console.error('An unknown error has occurred, please file a bug report at:');
console.log('https://github.com/sql-formatter-org/sql-formatter/issues\n');
throw e;
});

}
}

exitWhenIOError(e, infile) {
Expand Down

0 comments on commit 3518fcc

Please sign in to comment.