Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
engiefox opened this issue Sep 27, 2024 · 20 comments · Fixed by #4200
Closed
1 task done
Labels
Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN

Comments

@engiefox
Copy link

engiefox commented Sep 27, 2024

Is there an existing issue for this?

  • I have searched the existing issues

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)

.Select(acfFile => acfParser.Deserialize<SteamGame>(File.OpenRead(acfFile))

@HebaruSan HebaruSan added Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN labels Sep 27, 2024
@ZolderonGitHub

This comment was marked as duplicate.

@Halbann

This comment was marked as duplicate.

@HebaruSan HebaruSan pinned this issue Sep 27, 2024
@HebaruSan HebaruSan changed the title [Bug]: Unhandled Exception on startup [Bug]: ValveKeyValue.KeyValueException: Found end of file when another token type was expected Sep 27, 2024
@HebaruSan
Copy link
Member

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

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!

@HebaruSan HebaruSan added the Needs more info We need more info label Sep 27, 2024
@Halbann
Copy link

Halbann commented Sep 27, 2024

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

This comment was marked as off-topic.

@HebaruSan
Copy link
Member

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
Copy link

kretze commented Sep 27, 2024

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
Copy link
Member

@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
Copy link
Author

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

@engiefox
Copy link
Author

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

@HebaruSan
Copy link
Member

Hi @engiefox, thanks! The best thing to do first is to test the fix as explained in my comment above: #4197 (comment)

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

@JonnyOThan
Copy link
Contributor

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
Copy link
Author

No issues with the dev build

@kretze
Copy link

kretze commented Sep 28, 2024

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
Copy link
Member

@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
Copy link
Author

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
Copy link

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

@sizilium
Copy link

sizilium commented Oct 5, 2024

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
Copy link
Member

HebaruSan commented Oct 5, 2024

@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
Copy link

sizilium commented Oct 6, 2024

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

@HebaruSan HebaruSan unpinned this issue Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants