invoke method

Future invoke(
  1. Future hookAction(
    1. HHCtxI ctx
    ),
  2. bool handleCtrlException
)

Implementation

Future<dynamic> invoke(
  Future<dynamic> Function(HHCtxI ctx) hookAction,
  bool handleCtrlException,
) async {
  try {
    return await hookAction(ctx);
  } on HHCtrlException catch (e) {
    if (!handleCtrlException) {
      rethrow;
    }

    // Handle control flow exception
    switch (e.nextPhase) {
      case NextPhase.f_continue:
        // Continue to next hook
        return null;

      case NextPhase.f_skip:
        // Skip applies to hook batches - rethrow to outer rim
        rethrow;

      case NextPhase.f_break:
        // Break should throw - rethrow to outer handler
        rethrow;

      case NextPhase.f_delete:
        // Delete key and rethrow
        if (ctx.payload.key != null) {
          // Key deletion will be handled at outer level
        }
        rethrow;

      case NextPhase.f_pop:
        // Pop key and rethrow
        if (ctx.payload.key != null) {
          // Key pop will be handled at outer level
        }
        rethrow;

      case NextPhase.f_panic:
        // Throw runtime exception instead
        throw HHRuntimeException('Panic in hook execution: ${e.runtimeMeta}');
    }
  }
}