anchor.diff:  
     @override
     void visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
  -    final functionName = node.function.toSource();
  -    if (withinClass == ClassType.none && !functionName.startsWith('use')) {
  -      if (functionName == 'watch' && withinScopedProvider) {
  +    try {
  +      final functionName = node.function.toSource();
  +      if (withinClass == ClassType.none && !functionName.startsWith('use')) {
  +        if (functionName == 'watch' && withinScopedProvider) {
  +          yieldPatch('ref.watch', node.function.offset, node.function.end);
  +        }
  +        migrateStateProvider(node.argumentList.arguments.first);
  +
  +        super.visitFunctionExpressionInvocation(node);
  +        return;
  +      }
  +      if (functionName == 'watch' || functionName == 'useProvider') {
  +        foundProviderUsage.last = true;
  +        migrateStateProvider(node.argumentList.arguments.first);
  +        // watch(provider) => watch(provider.notifier)
  +        // useProvider(provider) => useProvider(provider.notifier)
           yieldPatch('ref.watch', node.function.offset, node.function.end);
  -      }
  -      migrateStateProvider(node.argumentList.arguments.first);
  -
  -      super.visitFunctionExpressionInvocation(node);
  -      return;
  -    }
  -    if (functionName == 'watch' || functionName == 'useProvider') {
  -      foundProviderUsage.last = true;
  -      migrateStateProvider(node.argumentList.arguments.first);
  -      // watch(provider) => watch(provider.notifier)
  -      // useProvider(provider) => useProvider(provider.notifier)
  -      yieldPatch('ref.watch', node.function.offset, node.function.end);
  -    } else if (functionName.startsWith('use')) {
  +      } else if (functionName.startsWith('use')) {
  +        final func = ProviderFunction(
  +          name: node.staticElement!.name,
  +          path: node.staticElement!.declaration.location!.components.join('/'),
  +          line: node.staticElement!.declaration.nameOffset,
  +        );
  +        migrateStateProvider(node.argumentList.arguments.first);
  +
  +        if (RiverpodProviderUsageInfo.shouldMigrate(func)) {
  +          migrateFunctionCall(node.argumentList);
  +          foundProviderUsage.last = true;
  +        }
  +      } else if (functionName == 'read') {
  +        foundProviderUsage.last = true;
  +        migrateStateProvider(node.argumentList.arguments.first);
  +
  +        // watch(provider) => watch(provider.notifier)
  +        // useProvider(provider) => useProvider(provider.notifier)
  +        yieldPatch('ref.read', node.function.offset, node.function.end);
  +      }
  +    } catch (e, st) {
  +      addError('when visiting function expression invocation\n$e\n$st');
  +    }
  +    super.visitFunctionExpressionInvocation(node);
  +  }
  +
  +  @override
  +  void visitFunctionDeclaration(FunctionDeclaration node) {
  +    try {
         final func = ProviderFunction(
  -        name: node.staticElement!.name,
  -        path: node.staticElement!.declaration.location!.components.join('/'),
  -        line: node.staticElement!.declaration.nameOffset,
  +        name: node.name.name,
  +        path: node.declaredElement!.declaration.location!.components.join('/'),
  +        line: node.name.offset,
         );
  -      migrateStateProvider(node.argumentList.arguments.first);
  -
         if (RiverpodProviderUsageInfo.shouldMigrate(func)) {
  -        migrateFunctionCall(node.argumentList);
  -        foundProviderUsage.last = true;
  -      }
  -    } else if (functionName == 'read') {
  -      foundProviderUsage.last = true;
  -      migrateStateProvider(node.argumentList.arguments.first);
  -
  -      // watch(provider) => watch(provider.notifier)
  -      // useProvider(provider) => useProvider(provider.notifier)
  -      yieldPatch('ref.read', node.function.offset, node.function.end);
  -    }
  -
  -    super.visitFunctionExpressionInvocation(node);
  -  }
  -
  -  @override
  -  void visitFunctionDeclaration(FunctionDeclaration node) {
  -    final func = ProviderFunction(
  -      name: node.name.name,
  -      path: node.declaredElement!.declaration.location!.components.join('/'),
  -      line: node.name.offset,
  -    );
  -    if (RiverpodProviderUsageInfo.shouldMigrate(func)) {
  -      migrateFunctionDeclaration(node);
  -    }
  -
  -    functionDecls[node.name.name] = node;
  -    migrateOnChangeFunction(node.name.name);
  +        migrateFunctionDeclaration(node);
  +      }
  +
  +      functionDecls[node.name.name] = node;
  +      migrateOnChangeFunction(node.name.name);
  +    } catch (e, st) {
  +      addError('before visiting function declaration\n$e\n$st');
  +    }
       super.visitFunctionDeclaration(node);
     }
   
     @override
     void visitMethodDeclaration(MethodDeclaration node) {
  -    if (node.name.name == 'build') {
  -      buildParams = node.parameters;
  -      functionBody = node.body;
  -      if (withinClass == ClassType.consumer) {
  -        // Consumer should be migrated regardless if providers are watched / read or not
  -        migrateParams(buildParams);
  -      }
  -    } else if (node.name.name == 'didUpdateProvider') {
  -      yieldPatch(
  -          ', ProviderContainer container',
  -          node.parameters!.parameters.last.end,
  -          node.parameters!.parameters.last.end);
  -      yieldPatch(', Object? oldValue, ', node.parameters!.parameters.first.end,
  -          node.parameters!.parameters.last.offset);
  -    }
  -    final func = ProviderFunction(
  -      name: node.name.name,
  -      path: node.declaredElement!.declaration.location!.components.join('/'),
  -      line: node.name.offset,
  -    );
  -    if (node.name.name != 'build' &&
  -        RiverpodProviderUsageInfo.shouldMigrate(func)) {
  -      migrateMethodDeclaration(node);
  -    }
  -
  -    methodDecls[node.name.name] = node;
  -    migrateOnChangeFunction(node.name.name);
  +    try {
  +      if (node.name.name == 'build') {
  +        buildParams = node.parameters;
  +        functionBody = node.body;
  +        if (withinClass == ClassType.consumer) {
  +          // Consumer should be migrated regardless if providers are watched / read or not
  +          migrateParams(buildParams);
  +        }
  +      } else if (node.name.name == 'didUpdateProvider') {
  +        yieldPatch(
  +            ', ProviderContainer container',
  +            node.parameters!.parameters.last.end,
  +            node.parameters!.parameters.last.end);
  +        yieldPatch(
  +            ', Object? oldValue, ',
  +            node.parameters!.parameters.first.end,
  +            node.parameters!.parameters.last.offset);
  +      }
  +      final func = ProviderFunction(
  +        name: node.name.name,
  +        path: node.declaredElement!.declaration.location!.components.join('/'),
  +        line: node.name.offset,
  +      );
  +      if (node.name.name != 'build' &&
  +          RiverpodProviderUsageInfo.shouldMigrate(func)) {
  +        migrateMethodDeclaration(node);
  +      }
  +
  +      methodDecls[node.name.name] = node;
  +      migrateOnChangeFunction(node.name.name);
  +    } catch (e, st) {
  +      addError('before visiting method declaration\n$e\n$st');
  +    }
       super.visitMethodDeclaration(node);
     }
   
  
positive.code:   }
  
    void migrateStateProvider(Expression expression) {
      if (expression.staticType
              ?.getDisplayString(withNullability: true)
              .contains('StateProvider') ??
          false) {
        yieldPatch('.state', expression.end, expression.end);
      }
    }
  
    void migrateStateful(String statefulName) {
      final statefulDeclaration = statefulDeclarations[statefulName];
      if (statefulDeclaration != null) {
        yieldPatch(
            'ConsumerStatefulWidget',
            statefulDeclaration.extendsClause!.superclass.offset,
            statefulDeclaration.extendsClause!.superclass.end);
        final method = statefulDeclaration.members.firstWhereOrNull((m) =>
                m is MethodDeclaration && m.name.name.contains('createState'))
            as MethodDeclaration?;
  
        if (method != null &&
            method.returnType != null &&
            method.returnType!.toSource().contains('State<StatefulWidget>')) {
          yieldPatch('ConsumerState<ConsumerStatefulWidget>',
              method.returnType!.offset, method.returnType!.end);
        }
      } else {
        statefulNeedsMigration.add(statefulName);
      }
    }
  
    void migrateOnChangeFunction(String functionName) {
      final methodDecl = methodDecls[functionName];
      if (methodDecl != null && functionNeedsMigration.contains(functionName)) {
        if (methodDecl.parameters?.parameters[1] is SimpleFormalParameter) {
          final parameter =
              methodDecl.parameters!.parameters[1] as SimpleFormalParameter;
          final type =
              parameter.type!.type!.getDisplayString(withNullability: false);
          yieldPatch(
              '$type? previous,',
              methodDecl.parameters!.parameters.first.offset,
              methodDecl.parameters!.parameters[1].offset);
        } else {
          addError(
              'failed to migrate listen function ${methodDecl.parameters?.toSource()}');
        }
      } else {
        final funcDecl = functionDecls[functionName];
        if (funcDecl != null && functionNeedsMigration.contains(functionName)) {
          if (funcDecl.functionExpression.parameters?.parameters[1]
              is SimpleFormalParameter) {
            final parameter = funcDecl.functionExpression.parameters!
                .parameters[1] as SimpleFormalParameter;
            final type =
                parameter.type!.type!.getDisplayString(withNullability: false);
            yieldPatch(
                '$type? previous,',
                funcDecl.functionExpression.parameters!.parameters.first.offset,
                funcDecl.functionExpression.parameters!.parameters[1].offset);
          } else {
            addError(
                'failed to migrate listen function ${funcDecl.functionExpression.parameters?.toSource()}');
          }
        }
      }
    }
  }
  
negative.code: 
    @override
    void visitFunctionExpression(FunctionExpression node) {
      try {
        if ((inConsumerBuilder || inHookBuilder) && lookingForBuilderParams) {
          lookingForBuilderParams = false;
          migrateParams(node.parameters);
        }
      } catch (e, st) {
        addError('before visiting function expression $node\n$e\n$st');
      }
      super.visitFunctionExpression(node);
    }
  