mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
better error message when os_file_overwrite fails
This commit is contained in:
parent
27e31f0475
commit
0cccba71d4
@ -45,6 +45,11 @@ const char *err_str(Error err) {
|
||||
case ErrorUnknownOperatingSystem: return "unrecognized operating system";
|
||||
case ErrorUnknownABI: return "unrecognized C ABI";
|
||||
case ErrorInvalidFilename: return "invalid filename";
|
||||
case ErrorDiskQuota: return "disk space quota exceeded";
|
||||
case ErrorDiskSpace: return "out of disk space";
|
||||
case ErrorUnexpectedWriteFailure: return "unexpected write failure";
|
||||
case ErrorUnexpectedSeekFailure: return "unexpected seek failure";
|
||||
case ErrorUnexpectedFileTruncationFailure: return "unexpected file truncation failure";
|
||||
}
|
||||
return "(invalid error)";
|
||||
}
|
||||
|
||||
@ -47,6 +47,11 @@ enum Error {
|
||||
ErrorUnknownOperatingSystem,
|
||||
ErrorUnknownABI,
|
||||
ErrorInvalidFilename,
|
||||
ErrorDiskQuota,
|
||||
ErrorDiskSpace,
|
||||
ErrorUnexpectedWriteFailure,
|
||||
ErrorUnexpectedSeekFailure,
|
||||
ErrorUnexpectedFileTruncationFailure,
|
||||
};
|
||||
|
||||
const char *err_str(Error err);
|
||||
|
||||
18
src/os.cpp
18
src/os.cpp
@ -2048,9 +2048,9 @@ Error os_file_overwrite(OsFile file, Buf *contents) {
|
||||
return ErrorNone;
|
||||
#else
|
||||
if (lseek(file, 0, SEEK_SET) == -1)
|
||||
return ErrorFileSystem;
|
||||
return ErrorUnexpectedSeekFailure;
|
||||
if (ftruncate(file, 0) == -1)
|
||||
return ErrorFileSystem;
|
||||
return ErrorUnexpectedFileTruncationFailure;
|
||||
for (;;) {
|
||||
if (write(file, buf_ptr(contents), buf_len(contents)) == -1) {
|
||||
switch (errno) {
|
||||
@ -2060,8 +2060,20 @@ Error os_file_overwrite(OsFile file, Buf *contents) {
|
||||
zig_unreachable();
|
||||
case EBADF:
|
||||
zig_unreachable();
|
||||
default:
|
||||
case EFAULT:
|
||||
zig_unreachable();
|
||||
case EDQUOT:
|
||||
return ErrorDiskQuota;
|
||||
case ENOSPC:
|
||||
return ErrorDiskSpace;
|
||||
case EFBIG:
|
||||
return ErrorFileTooBig;
|
||||
case EIO:
|
||||
return ErrorFileSystem;
|
||||
case EPERM:
|
||||
return ErrorAccess;
|
||||
default:
|
||||
return ErrorUnexpectedWriteFailure;
|
||||
}
|
||||
}
|
||||
return ErrorNone;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user