Skip to content

Fix type error in error handling callback: Convert args.first to String before int.parse() #1078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

PhuCG
Copy link

@PhuCG PhuCG commented Jun 30, 2025

Problem

The Errors JavaScript handler callback was causing a type error when trying to parse the error code: The argument type 'int' can't be assigned to the parameter type 'String'.

This occurred because args.first from JavaScript callbacks can be of type int, num, or String, but int.parse() only accepts String parameters.

Solution

Added .toString() conversion before calling int.parse() to ensure the argument is always a String, regardless of the original JavaScript type.

Before:

controller!.updateValue(
  controller!.value.copyWith(errorCode: int.parse(args.first)),
);

After:

final code = args.first.toString();
controller!.updateValue(
  controller!.value.copyWith(errorCode: int.parse(code)),
);

Benefits

  • ✅ Prevents runtime type errors
  • ✅ Handles all possible JavaScript return types safely
  • ✅ Maintains backward compatibility
  • ✅ Simple and readable solution

Testing

  • No compilation errors
  • Error codes are properly parsed and handled
  • Compatible with existing error handling logic

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Related Issues

Fixes type error in error handling callback when args.first is not a String.

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