Review error codes

This commit is contained in:
Raúl Marín 2023-12-18 10:40:02 +01:00
parent b269f87f4c
commit 65728f14ce
9 changed files with 11 additions and 18 deletions

View File

@ -179,13 +179,13 @@ private:
{
ptr = mmap(address_hint, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (MAP_FAILED == ptr)
throw ErrnoException(DB::ErrorCodes::CANNOT_ALLOCATE_MEMORY, "Allocator: Cannot mmap {}.", ReadableSize(size));
throw ErrnoException(DB::ErrorCodes::CANNOT_ALLOCATE_MEMORY, "Allocator: Cannot mmap {}", ReadableSize(size));
}
~Chunk()
{
if (ptr && 0 != munmap(ptr, size))
throw ErrnoException(DB::ErrorCodes::CANNOT_ALLOCATE_MEMORY, "Allocator: Cannot munmap {}.", ReadableSize(size));
throw ErrnoException(DB::ErrorCodes::CANNOT_MUNMAP, "Allocator: Cannot munmap {}", ReadableSize(size));
}
Chunk(Chunk && other) noexcept : ptr(other.ptr), size(other.size)

View File

@ -244,7 +244,7 @@ QueryProfilerBase<ProfilerImpl>::QueryProfilerBase(UInt64 thread_id, int clock_t
throw ErrnoException(ErrorCodes::CANNOT_MANIPULATE_SIGSET, "Failed to add signal to mask for query profiler");
if (sigaction(pause_signal, &sa, nullptr))
throw ErrnoException(ErrorCodes::CANNOT_MANIPULATE_SIGSET, "Failed to setup signal handler for query profiler");
throw ErrnoException(ErrorCodes::CANNOT_SET_SIGNAL_HANDLER, "Failed to setup signal handler for query profiler");
try
{

View File

@ -269,7 +269,7 @@ void ThreadFuzzer::setup() const
#endif
if (sigaction(SIGPROF, &sa, nullptr))
throw ErrnoException(ErrorCodes::CANNOT_MANIPULATE_SIGSET, "Failed to setup signal handler for thread fuzzer");
throw ErrnoException(ErrorCodes::CANNOT_SET_SIGNAL_HANDLER, "Failed to setup signal handler for thread fuzzer");
static constexpr UInt32 timer_precision = 1000000;

View File

@ -33,7 +33,7 @@ void createHardLink(const String & source_path, const String & destination_path)
if (source_descr.st_ino != destination_descr.st_ino)
ErrnoException::throwFromPathWithErrno(
ErrorCodes::CANNOT_STAT,
ErrorCodes::CANNOT_LINK,
destination_path,
link_errno,
"Destination file {} already exists and has a different inode",

View File

@ -52,11 +52,7 @@ AsynchronousReadBufferFromFile::AsynchronousReadBufferFromFile(
if (o_direct)
{
if (fcntl(fd, F_NOCACHE, 1) == -1)
ErrnoException::throwFromPath(
errno == ENOENT ? ErrorCodes::CANNOT_OPEN_FILE : ErrorCodes::CANNOT_OPEN_FILE,
file_name,
"Cannot set F_NOCACHE on file {}",
file_name);
ErrnoException::throwFromPath(ErrorCodes::CANNOT_OPEN_FILE, file_name, "Cannot set F_NOCACHE on file {}", file_name);
}
#endif
}

View File

@ -51,11 +51,7 @@ ReadBufferFromFile::ReadBufferFromFile(
if (o_direct)
{
if (fcntl(fd, F_NOCACHE, 1) == -1)
ErrnoException::throwFromPath(
errno == ENOENT ? ErrorCodes::CANNOT_OPEN_FILE : ErrorCodes::CANNOT_OPEN_FILE,
file_name,
"Cannot set F_NOCACHE on file {}",
file_name);
ErrnoException::throwFromPath(ErrorCodes::CANNOT_OPEN_FILE, file_name, "Cannot set F_NOCACHE on file {}", file_name);
}
#endif
}

View File

@ -46,7 +46,8 @@ WriteBufferFromFile::WriteBufferFromFile(
fd = ::open(file_name.c_str(), flags == -1 ? O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC : flags | O_CLOEXEC, mode);
if (-1 == fd)
ErrnoException::throwFromPath(ErrorCodes::CANNOT_OPEN_FILE, file_name, "Cannot open file {}", file_name);
ErrnoException::throwFromPath(
errno == ENOENT ? ErrorCodes::FILE_DOESNT_EXIST : ErrorCodes::CANNOT_OPEN_FILE, file_name, "Cannot open file {}", file_name);
#ifdef OS_DARWIN
if (o_direct)

View File

@ -137,7 +137,7 @@ void WriteBufferFromFileDescriptor::sync()
ProfileEvents::increment(ProfileEvents::FileSyncElapsedMicroseconds, watch.elapsedMicroseconds());
if (-1 == res)
ErrnoException::throwFromPath(ErrorCodes::CANNOT_WRITE_TO_FILE_DESCRIPTOR, getFileName(), "Cannot fsync {}", getFileName());
ErrnoException::throwFromPath(ErrorCodes::CANNOT_FSYNC, getFileName(), "Cannot fsync {}", getFileName());
}

View File

@ -92,7 +92,7 @@ struct SocketInterruptablePollWrapper
int err = ::close(epollfd);
chassert(!err || errno == EINTR);
throw ErrnoException(ErrorCodes::SYSTEM_ERROR, "Cannot epoll_create");
throw ErrnoException(ErrorCodes::SYSTEM_ERROR, "Cannot insert socket into epoll queue");
}
pipe_event.events = EPOLLIN | EPOLLERR | EPOLLPRI;
pipe_event.data.fd = pipe.fds_rw[0];