Make core:flags file open errors more readable

If it fails because the file doesn't exist:
[Open_File_Error#2] Unable to open "foo.file". File not found.

If it does exist and the flags are simple (.Read, .Write or both), it'll say this:
[Open_File_Error#2] Unable to open "foo.file" with perms 0o444 as read-only

It it does exist but fails to open for other reasons, it'll print:
[Open_File_Error#2] Unable to open "foo.file" with perms 0o444 and flags File_Flags{....}

Future work: Translate permissions from octal to `ls -al` format (e.g. `-rwxrwxrwx`).
This commit is contained in:
Jeroen van Rijn
2026-02-11 22:52:24 +01:00
parent b82512b4cf
commit b18f75c41c

View File

@@ -72,12 +72,37 @@ print_errors :: proc(data_type: typeid, error: Error, program: string, style: Pa
case Parse_Error:
fmt.wprintfln(stderr, "[%T.%v] %s", specific_error, specific_error.reason, specific_error.message)
case Open_File_Error:
fmt.wprintfln(stderr, "[%T#%i] Unable to open file with perms 0o%o and flags %v: %s",
specific_error,
specific_error.errno,
specific_error.perms,
specific_error.flags,
specific_error.filename)
if os.exists(specific_error.filename) {
flags: string
if specific_error.flags == {.Read} {
flags = "read-only"
} else if specific_error.flags == {.Write} {
flags = "write-only"
} else if specific_error.flags == {.Read, .Write} {
flags = "read/write"
}
if flags != "" {
fmt.wprintfln(stderr, "[%T#%i] Unable to open %q with perms 0o%o as %s",
specific_error,
specific_error.errno,
specific_error.filename,
u16(transmute(u32)specific_error.perms),
flags)
} else {
fmt.wprintfln(stderr, "[%T#%i] Unable to open %q with perms 0o%o and flags %v",
specific_error,
specific_error.errno,
specific_error.filename,
u16(transmute(u32)specific_error.perms),
specific_error.flags)
}
} else {
fmt.wprintfln(stderr, "[%T#%i] Unable to open %q. File not found",
specific_error,
specific_error.errno,
specific_error.filename)
}
case Validation_Error:
fmt.wprintfln(stderr, "[%T] %s", specific_error, specific_error.message)
case Help_Request: