vax_disassembler/error.rs
1//! # Disassembly Errors
2
3use thiserror::Error;
4use crate::{
5 opcode::{AccessType, DataType},
6 operand::Operand,
7};
8
9/// # VAX assembler/disassembler errors
10///
11/// # Examples
12///
13/// ```rust
14/// use std::io::Cursor;
15/// use vax_disassembler::{ReadMacro32, error::Error};
16///
17/// let invalid_opcode = Cursor::new([0x57]).disassemble();
18/// assert!(invalid_opcode.is_err());
19/// if let Err(Error::InvalidOpcode(0x57)) = invalid_opcode {} else { panic!(); }
20/// ```
21#[derive(Debug, Error)]
22pub enum Error {
23 /// # Invalid Opcode
24 ///
25 /// In the documention, all undefined opcodes are marked as "Reserved to DIGITAL", so this
26 /// error is like a reserved operand error.
27 #[error("Invalid opcode: {0:#X}")]
28 InvalidOpcode(u16),
29
30 /// # Invalid Opcode String
31 ///
32 /// In the documention, all undefined opcodes are marked as "Reserved to DIGITAL", so this
33 /// error is like a reserved operand error.
34 #[error("Invalid opcode: {0}")]
35 InvalidOpcodeString(String),
36
37 /// # Invalid Indexed Operand
38 ///
39 ///
40 #[error("Invalid indexed operand: {0:?}")]
41 InvalidIndexedOperand(Operand),
42
43 /// # Invalid Access Type and Data Type Combination
44 #[error("Invalid access type and data size: access = {0:?}, size = {0:?}")]
45 InvalidAccessSize(AccessType, DataType),
46
47 /// # Unimplemented Feature
48 ///
49 /// This is an unimplemented feature. This error should go away once development is complete.
50 #[error("Unimpleneted feature: {0}")]
51 Unimplemented(&'static str),
52
53 /// # Passtrhough I/O Error
54 #[error("I/O error: {0}")]
55 IoError(#[from] std::io::Error),
56}
57
58/// Error handling with the `Result` type for the [`enum@Error`] type.
59pub type Result<T> = std::result::Result<T, Error>;