os/error
The last error from a file or process operation: its code, its message and the path that failed.
import os.error
When an operation in the fs.file, fs.dir, os.process or os.temp packages fails, the detail is recorded here. After any operation that can fail, ask HasError and then Last to find out what happened.
The plain functions of the os package do not record errors here; they only return a code. This package is a different thing from the general-purpose error package.
Types
OSError
struct OSError| Name | Type | Description |
|---|---|---|
code | int = 0 | The error code; one of the constants above. |
message | str = "" | The error message, in English. |
operation | str = "" | The name of the function that failed. |
path | str = "" | The path that had the problem. |
system_code | int = 0 | The operating system's own error code (errno), where it is available. |
import os.error
import fs.file
func main:
error.Clear()
println error.HasError()
file.Delete("a file that does not exist.txt")
if error.HasError():
e := error.Last()
println e.code == error.FileNotFound, e.operation, e.message
println error.LastCode(), error.LastMessage()
end
error.Set(error.Timeout, "time ran out", "waiting", "", 0)
println error.LastCode() == error.Timeout, error.LastMessage()
println error.None, error.PermissionDenied, error.AlreadyExists, error.InvalidPath, error.NotSupported, error.IOError, error.ProcessFailed
endConstants and variables
None
const None: i32 = 0The example for this item is shown with the ones above: os-error-Last.salam
FileNotFound
const FileNotFound: i32 = 1The example for this item is shown with the ones above: os-error-Last.salam
PermissionDenied
const PermissionDenied: i32 = 2The example for this item is shown with the ones above: os-error-Last.salam
AlreadyExists
const AlreadyExists: i32 = 3The example for this item is shown with the ones above: os-error-Last.salam
InvalidPath
const InvalidPath: i32 = 4The example for this item is shown with the ones above: os-error-Last.salam
NotSupported
const NotSupported: i32 = 5The example for this item is shown with the ones above: os-error-Last.salam
IOError
const IOError: i32 = 6The example for this item is shown with the ones above: os-error-Last.salam
Timeout
const Timeout: i32 = 7The example for this item is shown with the ones above: os-error-Last.salam
ProcessFailed
const ProcessFailed: i32 = 8The example for this item is shown with the ones above: os-error-Last.salam
Functions
Set
func Set(code: int, message: str, operation: str, path: str, system_code: int)The example for this item is shown with the ones above: os-error-Last.salam
Clear
func Clear()The example for this item is shown with the ones above: os-error-Last.salam
Last
func Last(): OSErrorThe example for this item is shown with the ones above: os-error-Last.salam
LastCode
func LastCode(): intThe example for this item is shown with the ones above: os-error-Last.salam
LastMessage
func LastMessage(): strThe example for this item is shown with the ones above: os-error-Last.salam
HasError
func HasError(): boolThe example for this item is shown with the ones above: os-error-Last.salam