1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Define type for kernel error messages

Since the Go memory allocator is not available to us we need to define
our own error type.
This commit is contained in:
Achilleas Anagnostopoulos 2017-05-31 14:10:49 +01:00
parent 13d5f494e2
commit d5a4c43406
2 changed files with 32 additions and 0 deletions

18
kernel/error.go Normal file
View File

@ -0,0 +1,18 @@
package kernel
// Error describes a kernel kerror. All kernel errors must be defined as global
// variables that are pointers to the Error structure. This requirement stems
// from the fact that the Go allocator is not available to us so we cannot use
// errors.New.
type Error struct {
// The module where the error occurred.
Module string
// The error message
Message string
}
// Error implements the error interface.
func (e *Error) Error() string {
return e.Message
}

14
kernel/error_test.go Normal file
View File

@ -0,0 +1,14 @@
package kernel
import "testing"
func TestKernelError(t *testing.T) {
err := &Error{
Module: "foo",
Message: "error message",
}
if err.Error() != err.Message {
t.Fatalf("expected to err.Error() to return %q; got %q", err.Message, err.Error())
}
}