Skip to content

Commit

Permalink
Merge pull request #347 from ezioleq/NE-242
Browse files Browse the repository at this point in the history
Change thrown exception type in Window's class constructor
  • Loading branch information
Vixenka committed Oct 19, 2023
2 parents 334ed86 + 17a3165 commit 7a96cb8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions NoiseEngine.Native/src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pub mod conversions;
pub mod invalid_operation;
pub mod null_reference;
pub mod overflow;
pub mod platform_not_supported;
44 changes: 44 additions & 0 deletions NoiseEngine.Native/src/errors/platform_not_supported.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::{error::Error, fmt::Display};

use crate::interop::prelude::{ResultError, ResultErrorKind};

#[derive(Debug)]
pub struct PlatformNotSupportedError {
message: String,
}

impl PlatformNotSupportedError {
pub fn new(message: String) -> Self {
Self { message }
}

pub fn with_str(message: &str) -> Self {
Self::new(message.to_owned())
}
}

impl Default for PlatformNotSupportedError {
fn default() -> Self {
Self {
message: "Platform not supported.".to_string(),
}
}
}

impl Error for PlatformNotSupportedError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
}

impl Display for PlatformNotSupportedError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}

impl From<PlatformNotSupportedError> for ResultError {
fn from(err: PlatformNotSupportedError) -> Self {
ResultError::with_kind(&err, ResultErrorKind::PlatformNotSupported)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use cgmath::Vector2;

use crate::{
errors::invalid_operation::InvalidOperationError,
errors::platform_not_supported::PlatformNotSupportedError,
interop::prelude::{InteropOption, InteropResult, InteropString},
rendering::presentation::{input::InputData, window::Window, window_settings::WindowSettings},
};
Expand Down Expand Up @@ -31,7 +31,7 @@ extern "C" fn rendering_presentation_window_interop_create(

#[allow(unreachable_code)]
InteropResult::with_err(
InvalidOperationError::with_str("Window is not supported on this device.").into(),
PlatformNotSupportedError::with_str("Window is not supported on this device.").into(),
)
}

Expand Down
1 change: 1 addition & 0 deletions NoiseEngine.Native/src/interop/result_error_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub enum ResultErrorKind {
InvalidOperation = 3,
Overflow = 4,
Argument = 5,
PlatformNotSupported = 6,

GraphicsUniversal = 1000,
GraphicsInstanceCreate = 1001,
Expand Down
1 change: 1 addition & 0 deletions NoiseEngine/Interop/ResultError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ internal struct ResultError : IDisposable {
ResultErrorKind.InvalidOperation => new InvalidOperationException(Message, innerException),
ResultErrorKind.Overflow => new OverflowException(Message, innerException),
ResultErrorKind.Argument => new ArgumentException(Message, innerException),
ResultErrorKind.PlatformNotSupported => new PlatformNotSupportedException(Message, innerException),

ResultErrorKind.GraphicsUniversal => new GraphicsException(Message, innerException),
ResultErrorKind.GraphicsInstanceCreate => new GraphicsInstanceCreateException(Message, innerException),
Expand Down
1 change: 1 addition & 0 deletions NoiseEngine/Interop/ResultErrorKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal enum ResultErrorKind : uint {
InvalidOperation = 3,
Overflow = 4,
Argument = 5,
PlatformNotSupported = 6,

GraphicsUniversal = 1000,
GraphicsInstanceCreate = 1001,
Expand Down

0 comments on commit 7a96cb8

Please sign in to comment.