Skip to content

fix(common): make ResultType.mapError invoke its callback - #118

Merged
amaury901130 merged 1 commit into
mainfrom
fix/result-type-map-error
Sep 22, 2026
Merged

amaury901130 merged 1 commit into
mainfrom
fix/result-type-map-error

Conversation

@amaury901130

Copy link
Copy Markdown
Collaborator

Description

ResultType.mapError (modules/common/lib/core/result_type.dart) returned TError(e.error) without calling the callback. AuthCubit.login and signUp handle results like this:

authResult
  ..mapSuccess((_) => isLogin())
  ..mapError((failure) => isError(failure));

So on a TError, nothing was emitted and the cubit stayed in RLoading forever: the button kept spinning and no error was shown. The bug is hidden today only because the example AuthRepositoryImpl always succeeds. It surfaces as soon as a real backend returns an error.

Fix: mapError now calls the callback. If the callback returns an Exception, that replaces the error (transform semantics); anything else keeps the original error (side-effect semantics, as AuthCubit uses it). TSuccess is unaffected.

Also:

  • Adds modules/common/test/core/result_type_test.dart, the first tests in common, covering mapError and mapSuccess.
  • Adds modules/common/test to sonar.tests.

Issue

known-issues #1 in #117.

Preview

N/A

Notes:

🤖 Generated with Claude Code

mapError returned TError(e.error) without calling the callback, so
AuthCubit's `..mapError((f) => isError(f))` never ran and a failed
login/sign-up left the cubit in RLoading forever. The callback now runs;
an Exception it returns replaces the error, anything else keeps the
original.

Adds the first unit tests for common (ResultType) and registers
modules/common/test in sonar.tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@tarruk
tarruk self-requested a review September 22, 2026 19:50
@amaury901130
amaury901130 merged commit 74e2dd1 into main Sep 22, 2026
@amaury901130
amaury901130 deleted the fix/result-type-map-error branch September 22, 2026 20:06
amaury901130 added a commit that referenced this pull request Sep 22, 2026
- known-issues: mark #1 and #5 resolved, narrow #2 to the remaining env
  layout drift, update #3/#13 for the new common and domain tests
- overview, CLAUDE.md, feature guide: drop the mapError warning, describe
  the API_URL fallback
- testing, bootstrap customization: current test dirs and sonar.tests

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

2 participants