Skip to content
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

Improve thrown FormatException from int.parse when there is an "invalid radix-n" number #55665

Open
Luckey-Elijah opened this issue May 7, 2024 · 1 comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@Luckey-Elijah
Copy link

The following code throws a FormatException

void main() {
  final value = int.parse('1.0');
}

Full error:

Unhandled exception:
FormatException: Invalid radix-10 number (at character 1)
1.0
^

#0      int._handleFormatError (dart:core-patch/integers_patch.dart:126:5)
#1      int._parseRadix (dart:core-patch/integers_patch.dart:137:16)
#2      int._parse (dart:core-patch/integers_patch.dart:98:12)
#3      int.parse (dart:core-patch/integers_patch.dart:60:12)
#4      main (package:dpad/intparse.dart:2:21)
#5      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#6      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

It seems like the point to the incorrect character (1). Should it not be pointing to the . character (2) in this case?

Version

dart --version
Dart SDK version: 3.3.4 (stable) (Tue Apr 16 19:56:12 2024 +0000) on "macos_x64"
@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels May 9, 2024
@lrhn
Copy link
Member

lrhn commented May 12, 2024

In some cases, the parser doesn't know the point of failure, because it's written to be optimized for parsing correct numbers, and recording extra positions would be overhead. I don't know if this is one of those cases. Probably not.

Could probably have a second pass to look for invalid characters then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants