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

implement Display trait for most error types #513

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

bbogdan-ov
Copy link
Contributor

@bbogdan-ov bbogdan-ov commented Jan 13, 2025

This simple PR adds human readable Display implementation for most error types to simplify error handling

Namely for these types:

  • ShaderError
  • ShaderType
  • EglError
  • X11Error
  • Error in src/fs.rs
  • Error in src/native/module.rs

Error handling example:

let conf = miniquad::conf::Conf::default();

// `MyWindow::new()` returns `Result<MyWindow, ShaderError>`
miniquad::start(conf, move || match MyWindow::new() {
    Ok(window) => Box::new(window),
    Err(e) => {
        eprintln!("Miniquad error: {e}");
        std::process::exit(1);
    }
});
#version 330

layout (location = 0) in vec2 in_pos;
layout (location = 1) in vec2 in_uv;

out vec2 uv;

void main() {
    uv = in_uv;
    I_MISSPELLED_VAR_NAME = vec4(in_pos, 0.0, 1.0);
}

Error message before:

Miniquad error: CompilationError { shader_type: Vertex, error_message: "0:10(2): error: `I_MISSPELLED_VAR_NAME' undeclared\n0:10(2): error: value of type vec4 cannot be assigned to variable of type error" }

After:

Miniquad error: Vertex shader error:
0:10(2): error: `I_MISSPELLED_VAR_NAME' undeclared
0:10(2): error: value of type vec4 cannot be assigned to variable of type error

EDIT: updated examples for more context

@not-fl3
Copy link
Owner

not-fl3 commented Jan 13, 2025

Thanks for PR!

@not-fl3 not-fl3 merged commit 0d40431 into not-fl3:master Jan 13, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants