[][src]Module sunrise_libuser::error

Error handling

Errors in Horizon/NX follow a specific format. They are encoded on a 32-bit integer, where the bottom 9 bits represent the module, while the top bits represent the "description". A Module is usually a sysmodule, with a few additional modules for specific libraries (Module 168 is userland crash, for instance). See the switchbrew Error Codes page for more information.

Such errors are nice, but have one small problem: they're missing backtraces. In libuser, we opted to use a failure enum. We have a different enum for every module, listing all of their error descriptions, and a big enum over all those module errors. This fine-grained approach makes error handling code nicer. For instance, writing a function returning an Error:

use sunrise_libuser::error::{KernelError, SmError, Error};
fn ret_err() -> Result<(), Error> {
   // Will automatically be converted to Error, the backtrace filled
   let _ = Err(KernelError::PortRemoteDead)?;
   let _ = Err(SmError::PermissionDenied)?;
   Ok(())
}

Matching on an error is similarly convenient:

use sunrise_libuser::error::{KernelError, Error};
match err {
   Ok(_) => (),
   Err(Error::Kernel(KernelError::PortRemoteDead, _)) => (),
   _ => ()
}

Structs

AhciError

AHCI driver errors.

FileSystemError

FileSystem driver errors.

HidError

HID driver errors.

KernelError

Kernel syscall error codes.

LibuserError

Internal libuser errors.

LoaderError

Loader errors.

Module
PmError

PM Errors.

SmError

Service Manager errors.

TimeError

Time errors.

TwiliError

Twili Pipe errors.

ViError

Vi driver errors.

Enums

Error

The global error type. Every error defined here can be downcasted to this type. A Backtrace will be created when casting an error to this type.