Skip to content

YAML: Improve error handling#14261

Draft
chaoticgd wants to merge 4 commits intoPCSX2:masterfrom
chaoticgd:yaml_improvements
Draft

YAML: Improve error handling#14261
chaoticgd wants to merge 4 commits intoPCSX2:masterfrom
chaoticgd:yaml_improvements

Conversation

@chaoticgd
Copy link
Copy Markdown
Member

@chaoticgd chaoticgd commented Apr 5, 2026

Description of Changes

More YAML woes:

  • Rewrite YAML de-serialization code to prevent crashes in the case that the YAML tree is in a structure that we're not expecting (e.g. a node has a string value but an integer value was expected). Also prevent double lookups.
  • Try to recover from more types of errors during parsing.

TODO:

  • Same thing for folder memory cards.

Rationale behind Changes

Prevent crashes.

In #14207 I made a mistake where I thought the error callbacks I setup would be called after parsing was completed, however in that case a completely different set of error callbacks are used instead, so it should be safe to try and recover from all types of errors during parsing.

I'm quite surprised that RapidYAML's API makes what I'm doing here so complicated. It seems like it's very strongly geared towards throwing an exception or using setjmp/longjmp when there's any sort of problem, however to do that we'd need to call setjmp lower down the stack in the memory card code, and I don't really want to drastically change the memory card code out of a fear of breaking it. I just want to fix the crashes, and given we've got exceptions disabled I don't want to introduce more setjmp/longjmp mess.

Suggested Testing Steps

Test loading folder memory cards for various games. Test verifying game ISOs in the game properties dialog.

To make sure I didn't screw up game DB parsing in the happy case I wrote some code to dump the whole thing out so I could diff the results:

	std::stringstream ss;
	for (const auto& [name, entry] : s_game_db)
	{
		ss << "**** " << name << " ****\n";
		ss << "name: " << entry.name << "\n";
		ss << "name_sort: " << entry.name_sort << "\n";
		ss << "name_en: " << entry.name_en << "\n";
		ss << "region: " << entry.region << "\n";
		ss << "compat: " << static_cast<int>(entry.compat) << "\n";
		ss << "eeRoundMode: " << static_cast<int>(entry.eeRoundMode) << "\n";
		ss << "eeDivRoundMode: " << static_cast<int>(entry.eeDivRoundMode) << "\n";
		ss << "vu0RoundMode: " << static_cast<int>(entry.vu0RoundMode) << "\n";
		ss << "vu1RoundMode: " << static_cast<int>(entry.vu1RoundMode) << "\n";
		ss << "eeClampMode: " << static_cast<int>(entry.eeClampMode) << "\n";
		ss << "vu0ClampMode: " << static_cast<int>(entry.vu0ClampMode) << "\n";
		ss << "vu1ClampMode: " << static_cast<int>(entry.vu1ClampMode) << "\n";
		ss << "fixes: ";
		for (GamefixId fix : entry.gameFixes)
			ss << static_cast<int>(fix);
		ss << "\n";
		ss << "speedHacks: ";
		for (const auto& [key, value] : entry.speedHacks)
			ss << static_cast<int>(key) << "," << value << " ";
		ss << "\n";
		ss << "gsHWFixes: ";
		for (const auto& [key, value] : entry.gsHWFixes)
			ss << static_cast<int>(key) << "," << value << " ";
		ss << "\n";
		ss << "memcardFilters: ";
		for (const std::string& filter : entry.memcardFilters)
			ss << filter << " ";
		ss << "\n";
		ss << "patches: ";
		for (const auto& [name, patch] : entry.patches)
			ss << name << "," << patch << " ";
		ss << "\n";
		ss << "dynaPatches: ";
		for (const Patch::DynamicPatch& patch : entry.dynaPatches)
		{
			ss << patch.pattern.size() << "," << patch.replacement.size();
			for (const Patch::DynamicPatchEntry& entry : patch.pattern)
				ss << "," << entry.offset << "," << entry.value;
			for (const Patch::DynamicPatchEntry& entry : patch.replacement)
				ss << "," << entry.offset << "," << entry.value;
		}
		ss << "\n";
		ss << "\n";
	}
	FileSystem::WriteStringToFile("/tmp/gamedb_test.txt", ss.str());

Did you use AI to help find, test, or implement this issue or feature?

No.

@chaoticgd chaoticgd marked this pull request as draft April 5, 2026 11:57
@chaoticgd chaoticgd force-pushed the yaml_improvements branch from c7bfc26 to 67b06c0 Compare April 5, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant