kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Migrate core error handling from Vuex to a useAppError composable

Open rtibbles opened this issue 8 months ago • 1 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Complexity: High Target branch: develop

Context

The core Vuex module manages error state via handleError, handleApiError, and clearError actions, plus the CORE_SET_ERROR mutation and state.core.error. This is the most widely consumed piece of core Vuex state — ~95 files dispatch these actions across all plugins and core packages.

The error state is read by AppError.vue and NotificationsRoot/index.vue (both in the kolibri package) to render full-page error displays. It is written from plugin route handlers, composables, and components across the entire codebase.

Because the readers are specialized error-display components (not generic page wrappers), a shared composable is the right pattern — unlike loading state which is being moved to props.

Note: handleApiError currently re-throws the error after setting state, which has caused issues in route guards (see #11722 comment from @nucleogenesis). Reconsidering the throw behavior is out of scope for this issue but worth being aware of during implementation.

The Change

Create a useAppError composable in packages/kolibri/composables/ that exposes:

  • A reactive error ref
  • handleError(errorString) — sets error state
  • handleApiError({ error, reloadOnReconnect }) — handles API errors with disconnection detection
  • clearError() — clears error state

Update AppError.vue and NotificationsRoot to use the composable instead of mapState/mapActions. Update all ~95 consumer files across plugins and packages to import and call the composable functions instead of dispatching Vuex actions.

Remove the CORE_SET_ERROR mutation and the three actions from the core Vuex module.

Out of Scope

  • Changing the handleApiError re-throw behavior
  • Plugin-level Vuex module migration

Acceptance Criteria

  • [ ] useAppError composable exists in packages/kolibri/composables/
  • [ ] AppError.vue and NotificationsRoot use the composable, not Vuex
  • [ ] All consumer files updated to import from the composable instead of dispatching Vuex actions
  • [ ] handleError, handleApiError, clearError actions removed from core Vuex module
  • [ ] CORE_SET_ERROR mutation removed from core Vuex module
  • [ ] No remaining store.dispatch('handleError'...), store.dispatch('handleApiError'...), store.dispatch('clearError'), or mapActions(['clearError']) references
  • [ ] Existing test coverage updated

AI usage

This issue was drafted with Claude Code (Opus). The consumer inventory was produced by grepping the codebase. The composable approach was discussed and agreed upon with the maintainer — a shared composable fits because the error readers are specialized components, unlike loading which moved to props.

rtibbles avatar Apr 01 '26 00:04 rtibbles

Watching for resolution on behalf of learningequality/kolibri#14514.

rtibblesbot avatar Apr 04 '26 17:04 rtibblesbot