| // Copyright (C) 2016 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package rpc |
| |
| import ( |
| "fmt" |
| |
| "android.googlesource.com/platform/tools/gpu/framework/binary" |
| ) |
| |
| // Err is the interface implemented by errors that can be sent over the wire. |
| type Err interface { |
| binary.Object |
| Error() string |
| } |
| |
| // Error is an implementation of Err that holds a single string error message. |
| type Error struct { |
| binary.Generate `implements:"rpc.Err" java:"RpcError"` |
| Msg string |
| } |
| |
| func (e *Error) Error() string { return e.Msg } |
| |
| // ErrInvalidHeader is the error returned when the RPC call begins with an |
| // invalid header code. |
| type ErrInvalidHeader struct { |
| binary.Generate `implements:"rpc.Err"` |
| Header [4]byte |
| } |
| |
| func (e ErrInvalidHeader) Error() string { |
| return fmt.Sprintf("Invalid RPC header: %v", e.Header) |
| } |
| |
| // ErrDecodingCall is the error returned when a call cannot be decoded by the |
| // server. |
| type ErrDecodingCall struct { |
| binary.Generate `implements:"rpc.Err"` |
| Reason string |
| } |
| |
| func (e ErrDecodingCall) Error() string { |
| return fmt.Sprintf("Error decoding RPC call: %v", e.Reason) |
| } |
| |
| // ErrUnknownFunction is the error returned when a call is made to a function |
| // unrecognised by the server. |
| type ErrUnknownFunction struct { |
| binary.Generate `implements:"rpc.Err"` |
| Function string |
| } |
| |
| func (e ErrUnknownFunction) Error() string { |
| return fmt.Sprintf("Unknown RPC function: %v", e.Function) |
| } |
| |
| // ErrPanic is the error returned when an RPC call raises an uncaught panic. |
| type ErrPanic struct { |
| binary.Generate `implements:"rpc.Err"` |
| Msg string |
| } |
| |
| func (e ErrPanic) Error() string { |
| return fmt.Sprintf("RPC panic: %v", e.Msg) |
| } |