Skip to content

[flutter_tools] RangeError in TargetDeviceSelection.userSelectDevice #129191

Closed

Description

@christopherfujino

On beta/3.12.0

RangeError: RangeError (index): Invalid value: Not in inclusive range 0..1: -1
at List.[](growable_array.dart:264)
at TargetDeviceSelection.userSelectDevice(target_devices.dart:778)
at <asynchronous gap>(async)
at TargetDevicesWithExtendedWirelessDeviceDiscovery._selectFromDevicesAndCheckForWireless(target_devices.dart:707)
at <asynchronous gap>(async)
at RunCommand.validateCommand(run.dart:535)
at <asynchronous gap>(async)
at FlutterCommand.verifyThenRunCommand(flutter_command.dart:1481)
at <asynchronous gap>(async)
at FlutterCommand.run.<anonymous closure>(flutter_command.dart:1297)
at <asynchronous gap>(async)
at AppContext.run.<anonymous closure>(context.dart:150)
at <asynchronous gap>(async)
at CommandRunner.runCommand(command_runner.dart:212)
at <asynchronous gap>(async)
at FlutterCommandRunner.runCommand.<anonymous closure>(flutter_command_runner.dart:336)
at <asynchronous gap>(async)
at AppContext.run.<anonymous closure>(context.dart:150)
at <asynchronous gap>(async)
at FlutterCommandRunner.runCommand(flutter_command_runner.dart:284)
at <asynchronous gap>(async)
at run.<anonymous closure>.<anonymous closure>(runner.dart:115)
at <asynchronous gap>(async)
at AppContext.run.<anonymous closure>(context.dart:150)
at <asynchronous gap>(async)
at main(executable.dart:91)
at <asynchronous gap>(async)

I think the answer is to have an explicit check that this user input is a valid list index.

Activity

  1. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    c: crashStack traces logged to the console
    on Jun 20, 2023
  2. christopherfujino commented on Jun 20, 2023

    @christopherfujino
    ContributorAuthor
  3. andrewkolos commented on Jun 20, 2023

    @andrewkolos
    Contributor

    This code may or may not be relevant:

    Future<List<Device>?> findAllTargetDevices({

  4. self-assigned this
    on Jun 20, 2023
  5. vashworth commented on Jun 20, 2023

    @vashworth
    Contributor

    I think just need to add a check that deviceIndex >= 0

    if (deviceIndex < devices.length) {
    chosenDevice = devices[deviceIndex];
    }

    I think this is occuring because when it displays the list of devices like

    [1] My iPad
    [2] iPhone simulator
    

    If you type 0, it accepts it because it's a valid number, but it's not a valid device option

    final RegExp pattern = RegExp(r'\d+$|q', caseSensitive: false);

  6. eliasyishak commented on Jun 20, 2023

    @eliasyishak
    Contributor

    @vashworth thanks for the heads up! Seems simple enough, feel free to grab this PR if you have time today, I was planning on getting to this tomorrow

  7. eliasyishak commented on Jun 22, 2023

    @eliasyishak
    Contributor

    Closing with the following PR being merged into master

  8. github-actions commented on Jul 6, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  9. locked as resolved and limited conversation to collaborators on Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: crashStack traces logged to the consoletoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions