Skip to content

Commit

Permalink
handle corrupt config
Browse files Browse the repository at this point in the history
Differential Revision: D58844542

fbshipit-source-id: 7fe52e3b5c24b0c3cf79f1b8fa70cad1a36144f5
  • Loading branch information
David Heyer authored and facebook-github-bot committed Jul 2, 2024
1 parent d6dd0cc commit 0cfd81e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cookbooks/fb_choco/libraries/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,40 @@ module Config
SOURCES = '//sources/source'.freeze
FEATURES = '//features/feature'.freeze
CONFIG_LOC = 'C:\ProgramData\chocolatey\config\chocolatey.config'.freeze
DEFAULT_CONFIG = <<-EOF.strip.freeze
<?xml version="1.0" encoding="utf-8" ?>
<chocolatey>
<config>
<add key="cacheLocation" value="" />
<add key="containsLegacyPackageInstalls" value="true" />
<add key="commandExecutionTimeoutSeconds" value="2700" />
<add key="proxy" value="" />
<add key="proxyUser" value="" />
<add key="proxyPassword" value="" />
</config>
<sources>
<source id="chocolatey" value="https://community.chocolatey.org/api/v2/" />
</sources>
<features>
<feature name="checksumFiles" enabled="true" />
<feature name="autoUninstaller" enabled="false" />
<feature name="allowGlobalConfirmation" enabled="false" />
<feature name="failOnAutoUninstaller" enabled="false" />
<feature name="failOnStandardError" enabled="false" />
</features>
</chocolatey>
EOF

def config_state
@config_state ||= REXML::Document.new(@raw_config)
rescue StandardError => e
Chef::Log.warn(
"[fb_choco] Failed to parse chocolatey config due to #{e.to_s[0..300]}\n Using default config instead",
)
f = File.new(CONFIG_LOC, 'w')
f.write(DEFAULT_CONFIG)
f.close
@config_state = REXML::Document.new(DEFAULT_CONFIG)
end

def load_config
Expand Down

0 comments on commit 0cfd81e

Please sign in to comment.