Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change thrown exception type in Window's class constructor #347

Merged
merged 6 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading