← Back to issue list

State service doesn't catch permission errors in XDG_RUNTIME_DIR

View original Github issue

Metadata

Project
craft-application
Number
#869
Type
issue
State
open
Author
mr-cal
Labels
Type: Bug
Created
Updated
Closed
—

Current evaluation

StateService._get_state_dir calls platformdirs.user_runtime_path(ensure_exists=True), so a PermissionError in XDG_RUNTIME_DIR escapes as an internal traceback instead of falling back to util.get_home_temporary_directory() or recommending CRAFT_STATE_DIR. Still unfixed at HEAD; no comments or commits since.

Suggested action: keep open

Reason: The bug is still present at HEAD: craft_application/services/state.py:305-307 calls `platformdirs.user_runtime_path(str(os.getpid()), ensure_exists=True)` with no try/except around it, and `_create_state_dir` only catches `FileExistsError` ("Failed to create state dir at ... because a file with that name already exists"), so a PermissionError propagates as a raw internal error. `git log_path` on state.py shows only three commits (#786 feature, #838 g+rwx mode, #1084 ty lint) and none add permission handling. The issue carries the 'Type: Bug' label and a maintainer author, so it has been triaged and is valid, but it has zero comments and no assignee, and the choice between raising a friendly CRAFT_STATE_DIR error versus falling back to `util.get_home_temporary_directory()` still needs a maintainer decision.

Evaluated by: mr-cal-bot

Impact: 35 Quick Win: 21 Complexity: 20 Confidence: 88 Actionability: 75

Issue body

### What needs to get done If access to XDG_RUNTIME_DIR fails with a permission error, the state service should either raise a user-friendly error and recommend using CRAFT_STATE_DIR or fall back to `util.get_home_temporary_directory()`. ### Why it needs to get done Craft application raises an internal error when it fails to create a directory here: https://github.com/canonical/craft-application/blob/e0438e9b1d7db5cbe64c4b48ea92603becf011e4/craft_application/services/state.py#L298-L300 source: - https://treeherder.mozilla.org/logviewer?job_id=523533578&repo=autoland&task=GPQD26JzTRmaea_iieaqpA.0&lineNumber=233457 - https://matrix.to/#/!GGqzbFAUQprdPgYYCM:ubuntu.com/$zsIwY7Ln07TlXoNsY_WY-eQSSAXitSBqWga4ZMOwViM?via=ubuntu.com&via=matrix.org&via=kde.org

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha
Impact: 35
Quick Win: 21
Complexity: 20
Confidence: 88
Actionability: 75
keep open StateService._get_state_dir calls platformdirs.user_runtime_path(ensure_exists=True), so a PermissionError in XDG_RUNTIME_DIR escapes as an internal traceback instead of falling back to util.get_home_temporary_directory() or recommending CRAFT_STATE_DIR. Still unfixed at HEAD; no comments or commits since.
qwen/qwen3.6-35b-a3b
Impact: 45
Quick Win: 25
Complexity: 30
Confidence: 75
Actionability: 80
keep open State service crashes with unhandled PermissionError when XDG_RUNTIME_DIR is inaccessible; needs fallback or friendly error.
qwen/qwen3.8-27b
Impact: 45
Quick Win: 32
Staleness: 75
Complexity: 30
Confidence: 78
Support Request: 5
keep open State service crashes with an internal error when XDG_RUNTIME_DIR is not writable, since _create_state_dir only catches FileExistsError. Should raise a user-friendly error or fall back to the home temp dir. Unfixed at HEAD; no comments in over a year.
qwen/qwen3.6-35b-a3b
Staleness: 90
Complexity: 25
Confidence: 85
Support Request: 10
needs triage Unhandled permission errors in XDG_RUNTIME_DIR cause internal crashes in the state service. Suggests adding a fallback to CRAFT_STATE_DIR or a home temp directory. Currently untriaged with zero maintainer comments after 333 days.
qwen3.6-35b-a3b-mtp-q6
Staleness: 85
Complexity: 20
Confidence: 80
Support Request: 5
close stale State service crashes on XDG_RUNTIME_DIR permission errors instead of falling back or showing a friendly error. Issue has been inactive for over a year with no maintainer response.

Update history

No update history recorded yet.

Related work

  • Related To: canonical/craft-application#786 (confidence 80%)

    Commit 90d8dc1c 'feat: add a state service (#786)' introduced the _get_state_dir logic containing the unhandled permission path.

  • Related To: canonical/craft-application#838 (confidence 65%)

    Commit 6b237f12 'fix(StateService): add g+rwx to the state dir (#838)' addresses state dir permissions but does not wrap the user_runtime_path call; the unhandled path is still present at HEAD.

Related issues

No related issues found above the similarity threshold.