parse function Null safety

Future parse(
  1. CommandsPlugin commands,
  2. Context context,
  3. StringView toParse,
  4. Type expectedType,
  5. {Converter? converterOverride}

Attempt to parse a single argument from an argument view.

commands is the CommandsPlugin used for retrieving the converters for a specific Type. If no converter for expectedType is found, a NoConverterException is thrown.


Future<dynamic> parse(
  CommandsPlugin commands,
  Context context,
  StringView toParse,
  Type expectedType, {
  Converter<dynamic>? converterOverride,
}) async {
  Converter<dynamic>? converter = converterOverride ?? commands.converterFor(expectedType);
  if (converter == null) {
    throw NoConverterException(expectedType, context);

  try {
    dynamic parsed = await converter.convert(toParse, context);

    if (parsed == null) {
      throw BadInputException('Could not parse input $context to type "$expectedType"', context);

    return parsed;
  } on ParsingException catch (e) {
    throw BadInputException('Bad input $context: ${e.message}', context);