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

Failure is deprecated #12

Open
Nercury opened this issue May 3, 2020 · 2 comments
Open

Failure is deprecated #12

Nercury opened this issue May 3, 2020 · 2 comments

Comments

@Nercury
Copy link
Owner

Nercury commented May 3, 2020

rust-lang-deprecated/failure#347

@SpirosMakris
Copy link

Hi,
I'm going through the tutorial and I've stumbled upon this so I used the proposed replacements, thiserror for the auto Display trait functionality and anyhow in main file for "anyerror" type handling.

e.g shader.rs

use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
    #[error("Failed to load resource {}", name)]
    ResourceLoad {
        name: String,
        #[source]
        inner: resources::Error,
    },

    #[error("Can not determine shader type for resource {}", name)]
    CanNotDetermineShaderTypeForResource { name: String },

    #[error("Failed to compile shader {}: {}", name, message)]
    CompileError { name: String, message: String },

    #[error("Failed to link program {}: {}", name, message)]
    LinkError { name: String, message: String },
}

and main.rs (Truncated for brevity, showing mainly error handling)

use anyhow::{Error, Result};

fn run() -> Result<()> {


    let res = Resources::from_relative_exe_path(Path::new("assets")).unwrap();

    let sdl = sdl2::init().map_err(|message| Error::msg(message))?;
    let video = sdl.video().map_err(|message| Error::msg(message))?;
    
    .....

    let window = video
        .window("Game", 900, 700)
        .opengl()
        .resizable()
        .build()?;

    let _gl_context = window
        .gl_create_context()
        .map_err(|message| Error::msg(message))?;

    ....

    let shader_program = render_gl::Program::from_res(&gl, &res, "shaders/triangle")?;

     
    ...
   

    // Main loop
    let mut event_pump = sdl.event_pump().map_err(|message| Error::msg(message))?;

    'main: loop {
       ...
    }

    Ok(())
}

@Nercury
Copy link
Owner Author

Nercury commented Aug 10, 2020

Thanks for the update! It's good to know what is the current fashionable error handling crate is :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants