Skip to content

fix(logout): remove a corrupt session file instead of keeping it - #727

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/716-logout-corrupt-session
Oct 17, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/716-logout-corrupt-session

Conversation

@drawmeanelephant

Copy link
Copy Markdown
Contributor

Closes #716

A session file that fails to parse fell into the Not logged in. arm and stayed on disk, so cook logout could never remove it. SyncSession::load only errors when the file exists but can't be read/parsed, so that arm now warns, deletes the file, and reports the logout.

Test plan

  • garbage session.json + cook logout → warns, removes file, prints Logged out.
  • second cook logout → Not logged in.

@LeMyst LeMyst left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. SyncSession::load returns Err for an unreadable file, invalid JSON, or valid JSON with a malformed JWT, and the file is now removed in all three cases. If session.json is a directory, remove_file fails and the error surfaces cleanly.

  • Nit: the comment ("only fails when the file exists but cannot be read or parsed") leaves out the bad-JWT case.
  • Optional: a test with common::with_isolated_config would be easy.

🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.

A session file that fails to parse hit the `Not logged in.` arm and was
left on disk, so `cook logout` could never get rid of it and every
later command kept loading the same corrupt file. An unreadable file is
still a session file: warn, remove it, and report the logout.

Closes #716
@drawmeanelephant
drawmeanelephant force-pushed the fix/716-logout-corrupt-session branch 2 times, most recently from ec8983d to 60ef392 Compare October 14, 2026 13:27
@drawmeanelephant

Copy link
Copy Markdown
Contributor Author

Comment updated to cover the malformed-JWT case — load now reads "cannot be read, parsed, or turns out to hold a malformed token". Skipped the isolated-config test for now: logout resolves the session through global_config_path/COOK_CONFIG_DIR, so a test would just be re-asserting that plumbing.

@LeMyst
LeMyst merged commit f53a4dd into cooklang:main Oct 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cook logout cannot remove a corrupt session file

2 participants