summaryrefslogtreecommitdiff
path: root/internal/askcli/task_alias_cache.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-07 09:15:08 +0300
committerPaul Buetow <paul@buetow.org>2026-04-07 09:15:08 +0300
commit695b0b5c3572494c98c45fdacd74d777ab37d36e (patch)
treeaa8fafc57998d30d2d03e87aca216ac00896508d /internal/askcli/task_alias_cache.go
parent4185a422395bfe9d40c6f934fd56663d223bf782 (diff)
fix: recover gracefully from corrupted alias cache instead of hard-failing
When the task alias cache file contains invalid JSON (e.g. from a concurrent write race producing two concatenated JSON objects), the previous code returned a hard error that blocked all `ask` subcommands. Now loadTaskAliasCache discards the corrupt file and starts fresh, assigning new alias IDs on the next run. Validation errors (e.g. next_id reuse) still surface as errors since those indicate a logic bug. Also fix stale v1 reference in integration test aliasCachePath. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/askcli/task_alias_cache.go')
-rw-r--r--internal/askcli/task_alias_cache.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/internal/askcli/task_alias_cache.go b/internal/askcli/task_alias_cache.go
index 21967d8..e89dbb5 100644
--- a/internal/askcli/task_alias_cache.go
+++ b/internal/askcli/task_alias_cache.go
@@ -91,7 +91,11 @@ func loadTaskAliasCache() (taskAliasCache, string, error) {
var cache taskAliasCache
if err := json.Unmarshal(data, &cache); err != nil {
- return taskAliasCache{}, "", fmt.Errorf("parse task alias cache: %w", err)
+ // Cache file is unreadable (e.g. truncated write or duplicate-write
+ // corruption). Discard and start fresh — tasks will get new alias IDs on
+ // the next run, which is preferable to a hard failure.
+ _ = os.Remove(path)
+ return taskAliasCache{}, path, nil
}
if err := cache.validate(); err != nil {
return taskAliasCache{}, "", fmt.Errorf("validate task alias cache: %w", err)