KSP-CKAN / CKAN

The Comprehensive Kerbal Archive Network
https://forum.kerbalspaceprogram.com/index.php?/topic/197082-*
Other
1.99k stars 347 forks source link

[Bug]: ValveKeyValue.KeyValueException: Found end of file when another token type was expected #4197

Closed engiefox closed 1 month ago

engiefox commented 1 month ago

Is there an existing issue for this?

Operating System

Windows 11

CKAN Version

1.35.0

Games

KSP 1

Game Version

1.12.5

Did you make any manual changes to your game folder (i.e., not via CKAN)?

No

Describe the bug

Launching CKAN after updating to 1.35.0 from 1.34.4 fails to launch, only displaying a command window with the attached log

Steps to reproduce

  1. Have an .acf file in your Steam library with something weird about it (still investigating, but so far one user has found a file containing nothing but null bytes)
  2. Go to ckan.exe
  3. Click ckan.exe
  4. wait for error

Workaround

Delete corrupted .acf files from your Steam library

Relevant log output

Unhandled Exception: ValveKeyValue.KeyValueException: Found end of file when another token type was expected. ---> System.InvalidOperationException: Attempted to finalize object while in state InObjectBetweenKeyAndValue.
   at ValveKeyValue.Deserialization.KV1TextReader.FinalizeCurrentObject(Boolean explicit)
   at ValveKeyValue.Deserialization.KV1TextReader.FinalizeDocument()
   at ValveKeyValue.Deserialization.KV1TextReader.ReadObject()
   --- End of inner exception stack trace ---
   at ValveKeyValue.Deserialization.KV1TextReader.ReadObject()
   at ValveKeyValue.KVSerializer.Deserialize(Stream stream, KVSerializerOptions options)
   at CKAN.SteamLibrary.<>c__DisplayClass3_0.<LibraryPathGames>b__0(String acfFile)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at CKAN.SteamLibrary..ctor()
   at CKAN.GameInstanceManager..ctor(IUser user, IConfiguration configuration)
   at CKAN.CmdLine.MainClass.Execute(GameInstanceManager manager, CommonOptions opts, String[] args)
   at CKAN.CmdLine.MainClass.Main(String[] args)

https://github.com/KSP-CKAN/CKAN/blob/7568b2eb119ae8d929040add2bb5934d51a6068a/Core/SteamLibrary.cs#L60

ZolderonGitHub commented 1 month ago

Same problem here, is there any fix possible while the bug gets corrected?

Halbann commented 1 month ago

Also having this exception. My newly downloaded CKAN is at G:\Games\CKAN_2\ckan.exe and the path of my Steam install of KSP is G:\Games\Steam Library\steamapps\common\Kerbal Space Program, in case that's relevant. The path of my ACF file for KSP is G:\Games\Steam Library\steamapps\appmanifest_220200.acf. Could it be the space in the path?

HebaruSan commented 1 month ago

Hi @engiefox and @TheMainMan23 and @eecano and @kretze and @ZolderonGitHub and @Halbann, thanks for reporting this!

This error indicates a problem parsing one or more of the .acf files in your C:\Program Files (x86)\Steam\steamapps folder (or one of your other Steam library folders, if you have multiple) while CKAN is searching Steam for game instances. These files define the properties of your installed games, one per file, in Valve's proprietary KeyValue format (which looks oddly like KSP's .cfg format!), and typically they look like this:

Click to expand ![image](https://github.com/user-attachments/assets/0f009f7b-f9a9-4890-875a-ef9641461d85)

We will probably have to simply ignore parsing errors in this step (presumably with some logging so it's clear which files won't parse), but it would be best to figure out what specifically is going wrong with those files. If you're able to help, please put your .acf files in a ZIP file and share it here so we can analyze them. (Do NOT ZIP the entire folder, since that will include all of your games, which in addition to being a copyright infringement to share, would also be extremely large! Just the .acf files, please.) Or if you're comfortable browsing your .acf files in a text editor, feel free to do that instead or as well and let us know if you notice anything amiss.

Thanks!

Halbann commented 1 month ago

I stepped through the code and found it was just one acf file responsible that was just a few hundred null bytes with no text. I don't own the game it was for anymore. I deleted the file and CKAN worked fine after that.

Side note: the file was last modified in 2018 so it had obviously been there corrupted for some time without Steam cleaning it up.

kretze commented 1 month ago

I have several instances of ksp in my steam. All additional instances are added as a non-steam game. image

Original Kerbal Space Program image

Back then I created KSP_x64_start.exe files using a BAT-to-EXE converter by setting the SteamAppID before KSP.exe is started. So that the additional instances are registered as KSP in steam. I have no idea whether this still has an impact on the data stored in Steam.

Batch to exe Converter -> KSP_x64_start.exe @echo off set SteamAppId=220200 KSP_x64.exe -single-instance

image

Manifest File appmanifest_220200.acf.txt

HebaruSan commented 1 month ago

Hi @kretze, thanks for replying. The thing that would help us to investigate this would be a ZIP file containing all of your .acf files (just one .acf file tells us nothing because other ones could be corrupted and causing this error).

I'm going to "hide" your comment as off-topic because it introduces a number of topics that do not seem to be related to this issue thus far, and I don't want this discussion to get sidetracked. If you would like to discuss other things, please start a new issue. Thanks!

kretze commented 1 month ago

Problem found image

File deleted. CKAN can start without errors


Steam libraries were repeatedly transferred from PC / HDD to newer ones and integrated again. There must have been some old leftovers there.

HebaruSan commented 1 month ago

@kretze, cool! #4200 should address a zero-byte file as well.

For anyone still having this issue, the fix is in the dev build now (Settings→CKAN settings→Use dev builds to switch to them), and we will probably wait 3–7 days for the next stable release in case any other high priority issues come up.

engiefox commented 1 month ago

steamapps_acfs.zip Here is my bundle of acfs. I also have migrated drives, maybe that has something to do with it

engiefox commented 1 month ago

I have multiple drives, do you need acfs from all of them?

HebaruSan commented 1 month ago

Hi @engiefox, thanks! The best thing to do first is to test the fix as explained in my comment above: https://github.com/KSP-CKAN/CKAN/issues/4197#issuecomment-2379921085

We can look into these files if you still have issues with that build.

JonnyOThan commented 1 month ago

The dev build is accessible here: https://ksp-ckan.s3-us-west-2.amazonaws.com/ckan.exe

since you can’t launch ckan to get to the settings menu :p

engiefox commented 1 month ago

No issues with the dev build

kretze commented 1 month ago

I tested with the dev version. 2x 0 byte files created for testing. CKAN starts and skips the faulty files. But the cmd window disappears so quickly that you can't even see which files were affected. Maybe you should create a log for this, then you can check these files and/or fix the issue.

I just had to create a desktop recording so I could take a snipplet of the window. image

HebaruSan commented 1 month ago

@kretze, there's a --show-console command line option that keeps the window open after the GUI is started. If a person really needed to know which of their Steam files were corrupted, I would have them use that. But if alerting the user about such files isn't a priority for Steam, then it isn't one for CKAN either.

engiefox commented 1 month ago

Just located the offending file, it was an acf_back file called appmanifest_970960.acf_back and it was just an empty file. I checked the corresponding acf file with the same number and it was for Rebel Cops, don't know if that helps any.

cain666-4u commented 1 month ago

i couldnt find any corrupted files, but the dev build works

sizilium commented 1 month ago

FYI, dev build CKAN v1.35.1.24278 - KSP 1.12.5.3190 writes this to the console:

215 [1] WARN CKAN.SteamLibrary (null) - Failed to parse D:\\Steam\SteamApps\appmanifest_253250.acf:
ValveKeyValue.KeyValueException: Found end of file when another token type was expected. ---> System.InvalidOperationException: Attempted to finalize object while in state InObjectBetweenKeyAndValue.
   bei ValveKeyValue.Deserialization.KV1TextReader.FinalizeCurrentObject(Boolean explicit)
   bei ValveKeyValue.Deserialization.KV1TextReader.FinalizeDocument()
   bei ValveKeyValue.Deserialization.KV1TextReader.ReadObject()
   --- Ende der internen Ausnahmestapelüberwachung ---
   bei ValveKeyValue.Deserialization.KV1TextReader.ReadObject()
   bei ValveKeyValue.KVSerializer.Deserialize(Stream stream, KVSerializerOptions options)
   bei CKAN.SteamLibrary.<>c__DisplayClass6_0.<LibraryPathGames>b__0(String acfFile)
   bei CKAN.Utilities.DefaultIfThrows[T](Func`1 func, Func`2 onThrow)
257 [1] WARN CKAN.SteamLibrary (null) - Failed to parse D:\\Steam\SteamApps\appmanifest_724180.acf:
ValveKeyValue.KeyValueException: Found end of file when another token type was expected. ---> System.InvalidOperationException: Attempted to finalize object while in state InObjectBetweenKeyAndValue.
   bei ValveKeyValue.Deserialization.KV1TextReader.FinalizeCurrentObject(Boolean explicit)
   bei ValveKeyValue.Deserialization.KV1TextReader.FinalizeDocument()
   bei ValveKeyValue.Deserialization.KV1TextReader.ReadObject()
   --- Ende der internen Ausnahmestapelüberwachung ---
   bei ValveKeyValue.Deserialization.KV1TextReader.ReadObject()
   bei ValveKeyValue.KVSerializer.Deserialize(Stream stream, KVSerializerOptions options)
   bei CKAN.SteamLibrary.<>c__DisplayClass6_0.<LibraryPathGames>b__0(String acfFile)
   bei CKAN.Utilities.DefaultIfThrows[T](Func`1 func, Func`2 onThrow)

WIndows 10. It seems to work though.

HebaruSan commented 1 month ago

@sizilium yup, it's supposed to do that for people with corrupted files so we can tell which files are corrupted and what problems they caused. If you don't like it, you can delete those files (after inspecting them to confirm they're corrupted).

sizilium commented 1 month ago

@HebaruSan thx, I can confirm the file is corrupt and will delete it (content is 00...00)