git-gemini-forge 0.6.1

A simple Gemini server that serves a read-only view of public repositories from a Git forge.
use crate::network::ForgeApiKind;
use strum::{IntoEnumIterator, ParseError};

/// The ways that retrieving config values might fail.
#[derive(Debug)]
pub enum Error {
	/// Invalid value for env var `FORGE_TYPE`.
	BadPlatformType(strum::ParseError),

	/// The value provided for env var `FORGE_URL` is not a valid URL.
	BadUrl(url::ParseError),
}

impl core::fmt::Display for Error {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		// Describe the various kinds of errors:
		match self {
			Self::BadPlatformType(err) => {
				let options: Vec<ForgeApiKind> = ForgeApiKind::iter().collect();
				match err {
					ParseError::VariantNotFound => {
						write!(f, "Platform type must be one of {:?}", options)
					}
				}
			}
			Self::BadUrl(err) => write!(f, "Invalid source URL was given: {err}"),
		}
	}
}

impl From<url::ParseError> for Error {
	fn from(value: url::ParseError) -> Self {
		Self::BadUrl(value)
	}
}

impl From<strum::ParseError> for Error {
	fn from(value: strum::ParseError) -> Self {
		Self::BadPlatformType(value)
	}
}

impl std::error::Error for Error {}