Skip to content

Commit

Permalink
fix: ignore failed config file reads (#5118)
Browse files Browse the repository at this point in the history
Currently, we will try to read configuration from disk and leave any
exceptions unhandled. This can result in unexpected bailing when the
file cannot be read for whatever reason.

This change will ignore such failures, treating them the same as if the
path didn't exist.

Fixes #5117
  • Loading branch information
43081j authored Aug 26, 2024
1 parent 56ea360 commit aabfc23
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ export default class Configurations {
return undefined
}

public parseConfigurationModel(filepath: string | undefined): ConfigurationModel {
public parseConfigurationModel(filepath: string | undefined, filecontents?: string): ConfigurationModel {
if (!filepath || !fs.existsSync(filepath)) return new ConfigurationModel()
let parser = new ConfigurationModelParser(filepath)
let content = fs.readFileSync(filepath, 'utf8')
let content = filecontents || fs.readFileSync(filepath, 'utf8')
let uri = URI.file(filepath).toString()
parser.parse(content)
if (!isFalsyOrEmpty(parser.errors)) {
Expand Down Expand Up @@ -240,8 +240,14 @@ export default class Configurations {
public addFolderFile(configFilePath: string, fromCwd = false, resource?: string): boolean {
let folder = normalizeFilePath(path.resolve(configFilePath, '../..'))
if (this._configuration.hasFolder(folder) || !fs.existsSync(configFilePath)) return false
let configFile: string
try {
configFile = fs.readFileSync(configFilePath, 'utf8')
} catch (_err) {
return false
}
this.watchFile(configFilePath, ConfigurationTarget.WorkspaceFolder)
let model = this.parseConfigurationModel(configFilePath)
let model = this.parseConfigurationModel(configFilePath, configFile)
this._configuration.addFolderConfiguration(folder, model, resource)
logger.info(`Add folder configuration from ${fromCwd ? 'cwd' : 'file'}:`, configFilePath)
return true
Expand Down

0 comments on commit aabfc23

Please sign in to comment.