Skip to content

Commit 0e19170

Browse files
committed
Replace error strings with Error trait descriptions
1 parent d737dd4 commit 0e19170

File tree

3 files changed

+22
-36
lines changed

3 files changed

+22
-36
lines changed

src/defines.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,23 @@ impl Display for AfError {
8484
impl Error for AfError {
8585
fn description(&self) -> &str {
8686
match *self {
87-
AfError::SUCCESS => "Function returned successfully",
88-
AfError::ERR_NO_MEM => "The system or device ran out of memory",
89-
AfError::ERR_DRIVER => "Device driver error",
90-
AfError::ERR_RUNTIME => "Error in runtime environment",
91-
AfError::ERR_INVALID_ARRAY => "Input is not a valid Array Object",
92-
AfError::ERR_ARG => "One of the function arguments is incorrect",
93-
AfError::ERR_SIZE => "The size is incorrect",
94-
AfError::ERR_TYPE => "The type is not supported by this function",
95-
AfError::ERR_DIFF_TYPE => "The type of input arrays are not compatible",
96-
AfError::ERR_BATCH => "Function does not support GFOR / batch mode",
97-
AfError::ERR_DEVICE => "Array does not belong to device",
98-
AfError::ERR_NOT_SUPPORTED => "The option is not supported",
87+
AfError::SUCCESS => "Function returned successfully",
88+
AfError::ERR_NO_MEM => "System or Device ran out of memory",
89+
AfError::ERR_DRIVER => "Error in the device driver",
90+
AfError::ERR_RUNTIME => "Error with the runtime environment",
91+
AfError::ERR_INVALID_ARRAY => "Iput Array is not a valid object",
92+
AfError::ERR_ARG => "One of the function arguments is incorrect",
93+
AfError::ERR_SIZE => "Size is incorrect",
94+
AfError::ERR_TYPE => "Type is not suppported by this function",
95+
AfError::ERR_DIFF_TYPE => "Type of the input arrays are not compatible",
96+
AfError::ERR_BATCH => "Function does not support GFOR / batch mode",
97+
AfError::ERR_DEVICE => "Input does not belong to the current device",
98+
AfError::ERR_NOT_SUPPORTED => "Unsupported operation/parameter option",
9999
AfError::ERR_NOT_CONFIGURED => "This build of ArrayFire does not support this feature",
100-
AfError::ERR_NO_DBL => "This device does not support double",
101-
AfError::ERR_NO_GFX => "This build of ArrayFire was not built with graphics or this device does not support graphics",
102-
AfError::ERR_INTERNAL => "There was an internal error in either ArrayFire or upstream project",
103-
AfError::ERR_UNKNOWN => "Unkown Error",
100+
AfError::ERR_NO_DBL => "This device does not support double",
101+
AfError::ERR_NO_GFX => "This build of ArrayFire has no graphics support",
102+
AfError::ERR_INTERNAL => "Eror either in ArrayFire or in a project upstream",
103+
AfError::ERR_UNKNOWN => "Unknown Error",
104104
}
105105
}
106106
}

src/error.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use defines::AfError;
2+
use std::error::Error;
23

34
pub type ErrorCallback = Fn(AfError);
45

@@ -12,22 +13,7 @@ pub fn register_error_handler(callback: &'static ErrorCallback) {
1213

1314
pub fn handle_error_general(error_code: AfError) {
1415
match error_code {
15-
AfError::SUCCESS => {}, /* No-op */
16-
AfError::ERR_NO_MEM => panic!("The system or device ran out of memory"),
17-
AfError::ERR_DRIVER => panic!("There was an error in the device driver"),
18-
AfError::ERR_RUNTIME => panic!("There was an error with the runtime environment"),
19-
AfError::ERR_INVALID_ARRAY => panic!("The input array is not a valid Array object"),
20-
AfError::ERR_ARG => panic!("One of the function arguments is incorrect"),
21-
AfError::ERR_SIZE => panic!("The size is incorrect"),
22-
AfError::ERR_TYPE => panic!("The type is not suppported by this function"),
23-
AfError::ERR_DIFF_TYPE => panic!("The type of the input arrays are not compatible"),
24-
AfError::ERR_BATCH => panic!("Function does not support GFOR / batch mode"),
25-
AfError::ERR_DEVICE => panic!("Input does not belong to the current device"),
26-
AfError::ERR_NOT_SUPPORTED => panic!("Unsupported operation/parameter option"),
27-
AfError::ERR_NOT_CONFIGURED => panic!("This build of ArrayFire does not support this feature"),
28-
AfError::ERR_NO_DBL => panic!("This device does not support double"),
29-
AfError::ERR_NO_GFX => panic!("This build of ArrayFire was not built with graphics or this device does not support graphics"),
30-
AfError::ERR_INTERNAL => panic!("There was an internal error either in ArrayFire or in a project upstream"),
31-
AfError::ERR_UNKNOWN => panic!("Unknown Error"),
16+
AfError::SUCCESS => {}, /* No-op */
17+
_ => panic!("Error message: {}", error_code.description()),
3218
}
33-
}
19+
}

src/index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ pub fn set_rows(input: &Array, new_rows: &Array, first: u64, last: u64) -> Array
187187
/// use arrayfire::{Dim4, randu, col, print};
188188
/// let dims = Dim4::new(&[5, 5, 1, 1]);
189189
/// let a = randu::<f32>(dims);
190-
/// println!("Grab last col of the random matrix");
191190
/// print(&a);
191+
/// println!("Grab last col of the random matrix");
192192
/// print(&col(&a, 4));
193193
/// ```
194194
#[allow(dead_code)]
@@ -406,4 +406,4 @@ impl SeqInternal {
406406
step: From::from(s.step()),
407407
}
408408
}
409-
}
409+
}

0 commit comments

Comments
 (0)