@@ -167,7 +167,7 @@ namespace {
167167
168168 // Validates and stores a single setting from the YAML document.
169169 template <Setting S>
170- void ValidateSetting (const YAML::Node& root, SettingsMap& map, std::vector<Warning>& warnings)
170+ void ValidateSetting (const YAML::Node& root, SettingsMap& map, const std::wstring& filePath, std::vector<Warning>& warnings)
171171 {
172172 constexpr auto path = details::SettingMapping<S>::YamlPath;
173173 auto node = NavigateYamlPath (root, path);
@@ -201,21 +201,23 @@ namespace {
201201 else
202202 {
203203 const auto widePath = MultiByteToWide (path);
204- warnings.push_back ({std::format (L" Warning: Invalid value for setting '{}'. Using default." , widePath), widePath});
204+ warnings.push_back (
205+ {wsl::shared::Localization::WSLCUserSettings_Warning_InvalidValue (widePath, filePath, node->Mark ().line + 1 ), widePath});
205206 }
206207 }
207208 catch (...)
208209 {
209210 const auto widePath = MultiByteToWide (path);
210- warnings.push_back ({std::format (L" Warning: Invalid type for setting '{}'. Using default." , widePath), widePath});
211+ warnings.push_back (
212+ {wsl::shared::Localization::WSLCUserSettings_Warning_InvalidType (widePath, filePath, node->Mark ().line + 1 ), widePath});
211213 }
212214 }
213215
214216 // Validates all settings via a fold over the Setting enum index sequence.
215217 template <size_t ... S>
216- void ValidateAll (const YAML::Node& root, SettingsMap& map, std::vector<Warning>& warnings, std::index_sequence<S...>)
218+ void ValidateAll (const YAML::Node& root, SettingsMap& map, const std::wstring& filePath, std::vector<Warning>& warnings, std::index_sequence<S...>)
217219 {
218- (ValidateSetting<static_cast <Setting>(S)>(root, map, warnings), ...);
220+ (ValidateSetting<static_cast <Setting>(S)>(root, map, filePath, warnings), ...);
219221 }
220222
221223 // Collects the set of known dot-separated YAML paths from all SettingMapping specializations.
@@ -243,7 +245,12 @@ namespace {
243245 }
244246
245247 // Iteratively walks the YAML tree and warns about keys not in the known set.
246- void WarnUnknownKeys (const YAML::Node& root, const std::set<std::string>& knownPaths, const std::set<std::string>& knownPrefixes, std::vector<Warning>& warnings)
248+ void WarnUnknownKeys (
249+ const YAML::Node& root,
250+ const std::set<std::string>& knownPaths,
251+ const std::set<std::string>& knownPrefixes,
252+ const std::wstring& filePath,
253+ std::vector<Warning>& warnings)
247254 {
248255 // Stack of (node, prefix) pairs to process.
249256 std::vector<std::pair<YAML::Node, std::string>> stack;
@@ -264,7 +271,8 @@ namespace {
264271 catch (...)
265272 {
266273 auto location = prefix.empty () ? std::wstring (L" root" ) : MultiByteToWide (prefix);
267- warnings.push_back ({std::format (L" Warning: Non-string key in section '{}'." , location), location});
274+ warnings.push_back (
275+ {wsl::shared::Localization::WSLCUserSettings_Warning_NonStringKey (location, filePath, it->first .Mark ().line + 1 ), location});
268276 continue ;
269277 }
270278
@@ -281,14 +289,18 @@ namespace {
281289 {
282290 // Unknown section — warn once, don't traverse.
283291 const auto widePath = MultiByteToWide (fullPath);
284- warnings.push_back ({std::format (L" Warning: Unknown setting section '{}'." , widePath), widePath});
292+ warnings.push_back (
293+ {wsl::shared::Localization::WSLCUserSettings_Warning_UnknownSection (
294+ widePath, filePath, it->first .Mark ().line + 1 ),
295+ widePath});
285296 }
286297 }
287298 else if (!knownPaths.count (fullPath) && !knownPrefixes.count (fullPath))
288299 {
289300 // Unknown setting
290301 const auto widePath = MultiByteToWide (fullPath);
291- warnings.push_back ({std::format (L" Warning: Unknown setting '{}'." , widePath), widePath});
302+ warnings.push_back (
303+ {wsl::shared::Localization::WSLCUserSettings_Warning_UnknownKey (widePath, filePath, it->first .Mark ().line + 1 ), widePath});
292304 }
293305 }
294306 }
@@ -306,8 +318,7 @@ namespace {
306318 // emit a warning so the user understands why settings were ignored.
307319 if (err != ENOENT)
308320 {
309- warnings.push_back (
310- {std::format (L" Warning: Failed to open '{}', errno: {}. Using default settings." , path.filename ().wstring (), err), {}});
321+ warnings.push_back ({wsl::shared::Localization::WSLCUserSettings_Warning_FailedToOpen (path.wstring (), err), {}});
311322 }
312323
313324 return std::nullopt ;
@@ -320,7 +331,7 @@ namespace {
320331 catch (const std::exception& e)
321332 {
322333 warnings.push_back (
323- {std::format ( L" Warning: '{}' could not be parsed: {}. " , path. filename () .wstring (), MultiByteToWide (e.what ())), {}});
334+ {wsl::shared::Localization::WSLCUserSettings_Warning_ParseError (path .wstring (), MultiByteToWide (e.what ())), {}});
324335 return std::nullopt ;
325336 }
326337 }
@@ -350,23 +361,21 @@ UserSettings::UserSettings(const std::filesystem::path& settingsDir)
350361 if (root.has_value ())
351362 {
352363 m_type = UserSettingsType::Standard;
364+ const auto filePath = m_settingsPath.wstring ();
353365
354366 if (root->IsMap ())
355367 {
356368 constexpr auto settingCount = static_cast <size_t >(Setting::Max);
357- ValidateAll (root.value (), m_settings, m_warnings, std::make_index_sequence<settingCount>());
369+ ValidateAll (root.value (), m_settings, filePath, m_warnings, std::make_index_sequence<settingCount>());
358370
359371 constexpr auto indexSeq = std::make_index_sequence<settingCount>();
360372 auto knownPaths = CollectKnownPaths (indexSeq);
361373 auto knownPrefixes = CollectKnownPrefixes (knownPaths);
362- WarnUnknownKeys (root.value (), knownPaths, knownPrefixes, m_warnings);
374+ WarnUnknownKeys (root.value (), knownPaths, knownPrefixes, filePath, m_warnings);
363375 }
364376 else
365377 {
366- m_warnings.push_back (
367- {std::format (
368- L" Warning: '{}' is empty or has invalid structure. Expected a YAML mapping." , m_settingsPath.filename ().wstring ()),
369- {}});
378+ m_warnings.push_back ({wsl::shared::Localization::WSLCUserSettings_Warning_InvalidStructure (filePath), {}});
370379 }
371380 }
372381
0 commit comments