{% extends "layout.njk" %}

{% block main %}

use num_derive::FromPrimitive;
use thiserror::Error;

#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum {{ program.name | pascalCase }}Error {
{% for error in errors | sort(false, false, 'code') %}
    /// {{ error.code }} - {{ error.message }}
    #[error("{{ error.message }}")]
    {{ error.name | pascalCase }} = 0x{{ error.code.toString(16) | upper }},
{% endfor %}
}

impl From<{{ program.name | pascalCase }}Error> for solana_program_error::ProgramError {
    fn from(e: {{ program.name | pascalCase }}Error) -> Self {
        solana_program_error::ProgramError::Custom(e as u32)
    }
}

{% endblock %}
