function get_throw_errno_impl()

in src/os/_Private/Errno.php [16:68]


function get_throw_errno_impl(): (function(OS\Errno, string): noreturn) {
  $single_code = keyset[
    OS\ChildProcessException::class,
    OS\ConnectionAbortedException::class,
    OS\ConnectionRefusedException::class,
    OS\ConnectionResetException::class,
    OS\AlreadyExistsException::class,
    OS\NotFoundException::class,
    OS\IsADirectoryException::class,
    OS\IsNotADirectoryException::class,
    OS\ProcessLookupException::class,
    OS\TimeoutException::class,
  ];
  $multiple_codes = keyset[
    OS\BlockingIOException::class,
    OS\BrokenPipeException::class,
    OS\PermissionException::class,
  ];

  $throws = new \HH\Lib\Ref(dict[]);
  $add_code = (OS\Errno $code, (function(string): noreturn) $impl) ==> {
    invariant(
      !C\contains_key($throws->value, $code),
      '%s has multiple exception implementations',
      $code,
    );
    $throws->value[$code] = $impl;
  };

  foreach ($single_code as $class) {
    $code = $class::_getValidErrno();
    $add_code($code, $msg ==> {
      throw new $class($msg);
    });
  }
  foreach ($multiple_codes as $class) {
    foreach ($class::_getValidErrnos() as $code) {
      $add_code($code, $msg ==> {
        throw new $class($code, $msg);
      });
    }
  }

  $throws = $throws->value;

  return ($code, $message) ==> {
    $override = $throws[$code] ?? null;
    if ($override) {
      $override($message);
    }
    throw new OS\ErrnoException($code, $message);
  };
}