Remove unnecessary exports from ffi-errors

Also remove unused error code constants.
This commit is contained in:
Oliver Hamlet
2025-05-15 20:56:27 +01:00
parent 517dc6b43c
commit 13cc0842de
4 changed files with 62 additions and 148 deletions
+15 -37
View File
@@ -1,51 +1,29 @@
// Unless otherwise noted, these constants and the mapping logic are copied from
// esplugin-ffi.
use std::ffi::c_int;
use esplugin::Error;
#[unsafe(no_mangle)]
pub static ESP_ERROR_NULL_POINTER: c_int = 1;
const ESP_ERROR_PARSE_ERROR: c_int = 5;
#[unsafe(no_mangle)]
pub static ESP_ERROR_NOT_UTF8: c_int = 2;
const ESP_ERROR_NO_FILENAME: c_int = 7;
#[unsafe(no_mangle)]
pub static ESP_ERROR_STRING_CONTAINS_NUL: c_int = 3;
const ESP_ERROR_TEXT_DECODE_ERROR: c_int = 8;
#[unsafe(no_mangle)]
pub static ESP_ERROR_INVALID_GAME_ID: c_int = 4;
const ESP_ERROR_IO_ERROR: c_int = 10;
#[unsafe(no_mangle)]
pub static ESP_ERROR_PARSE_ERROR: c_int = 5;
const ESP_ERROR_FILE_NOT_FOUND: c_int = 11;
#[unsafe(no_mangle)]
pub static ESP_ERROR_PANICKED: c_int = 6;
const ESP_ERROR_IO_PERMISSION_DENIED: c_int = 12;
#[unsafe(no_mangle)]
pub static ESP_ERROR_NO_FILENAME: c_int = 7;
const ESP_ERROR_UNRESOLVED_RECORD_IDS: c_int = 13;
#[unsafe(no_mangle)]
pub static ESP_ERROR_TEXT_DECODE_ERROR: c_int = 8;
const ESP_ERROR_PLUGIN_METADATA_NOT_FOUND: c_int = 14;
#[unsafe(no_mangle)]
pub static ESP_ERROR_TEXT_ENCODE_ERROR: c_int = 9;
#[unsafe(no_mangle)]
pub static ESP_ERROR_IO_ERROR: c_int = 10;
#[unsafe(no_mangle)]
pub static ESP_ERROR_FILE_NOT_FOUND: c_int = 11;
#[unsafe(no_mangle)]
pub static ESP_ERROR_IO_PERMISSION_DENIED: c_int = 12;
#[unsafe(no_mangle)]
pub static ESP_ERROR_UNRESOLVED_RECORD_IDS: c_int = 13;
#[unsafe(no_mangle)]
pub static ESP_ERROR_PLUGIN_METADATA_NOT_FOUND: c_int = 14;
#[unsafe(no_mangle)]
pub static ESP_ERROR_UNKNOWN: c_int = c_int::MAX;
// This constant is not copied from esplugin-ffi, but does not conflict with any
// values defined there.
pub(crate) const ESP_ERROR_UNKNOWN: c_int = c_int::MAX;
#[expect(
clippy::wildcard_enum_match_arm,
@@ -60,7 +38,7 @@ fn map_io_error(err: &std::io::Error) -> c_int {
}
#[must_use]
pub fn map_error(err: &Error) -> c_int {
pub(crate) fn map_error(err: &Error) -> c_int {
match err {
Error::IoError(x) => map_io_error(x),
Error::NoFilename(_) => ESP_ERROR_NO_FILENAME,
+13 -28
View File
@@ -1,43 +1,28 @@
// Unless otherwise noted, these constants and the mapping logic are copied from
// loot-condition-interpreter-ffi.
use loot_condition_interpreter::Error;
use std::ffi::c_int;
/// Invalid arguments were given for the function.
#[unsafe(no_mangle)]
pub static LCI_ERROR_INVALID_ARGS: c_int = -1;
/// Something went wrong while parsing the condition expression.
#[unsafe(no_mangle)]
pub static LCI_ERROR_PARSING_ERROR: c_int = -2;
const LCI_ERROR_PARSING_ERROR: c_int = -2;
/// Something went wrong while getting the version of an executable.
#[unsafe(no_mangle)]
pub static LCI_ERROR_PE_PARSING_ERROR: c_int = -3;
const LCI_ERROR_PE_PARSING_ERROR: c_int = -3;
/// Some sort of I/O error occurred.
#[unsafe(no_mangle)]
pub static LCI_ERROR_IO_ERROR: c_int = -4;
const LCI_ERROR_IO_ERROR: c_int = -4;
/// Something panicked.
#[unsafe(no_mangle)]
pub static LCI_ERROR_PANICKED: c_int = -5;
/// The library encountered an error that should not have been possible to
/// encounter.
const LCI_ERROR_INTERNAL_LOGIC_ERROR: c_int = -8;
/// A thread lock was poisoned.
#[unsafe(no_mangle)]
pub static LCI_ERROR_POISONED_THREAD_LOCK: c_int = -6;
/// Failed to encode string as a C string, e.g. because there was a nul present.
#[unsafe(no_mangle)]
pub static LCI_ERROR_TEXT_ENCODE_FAIL: c_int = -7;
/// The library encountered an error that should not have been possible to encounter.
#[unsafe(no_mangle)]
pub static LCI_ERROR_INTERNAL_LOGIC_ERROR: c_int = -8;
#[unsafe(no_mangle)]
pub static LCI_ERROR_UNKNOWN: c_int = c_int::MAX;
// This constant is not copied from loot-condition-interpreter-ffi, but does not
// conflict with any values defined there.
pub(crate) const LCI_ERROR_UNKNOWN: c_int = c_int::MAX;
#[must_use]
pub fn map_error(err: &Error) -> c_int {
pub(crate) fn map_error(err: &Error) -> c_int {
match err {
Error::ParsingIncomplete(_) | Error::UnconsumedInput(_) | Error::ParsingError(_, _) => {
LCI_ERROR_PARSING_ERROR
+8 -22
View File
@@ -92,39 +92,25 @@
clippy::verbose_file_reads,
clippy::wildcard_enum_match_arm
)]
use std::{
error::Error,
ffi::{c_int, c_uchar},
};
use std::{error::Error, ffi::c_int};
use esplugin::ESP_ERROR_UNKNOWN;
use lci::LCI_ERROR_UNKNOWN;
use libloadorder::LIBLO_ERROR_UNKNOWN;
use libloot::error::{ConditionEvaluationError, LoadOrderError, PluginDataError};
pub mod esplugin;
pub mod lci;
pub mod libloadorder;
/// An error from esplugin.
#[unsafe(no_mangle)]
pub static LIBLOOT_SYSTEM_ERROR_CATEGORY_ESPLUGIN: c_uchar = 1;
/// An error from libloadorder.
#[unsafe(no_mangle)]
pub static LIBLOOT_SYSTEM_ERROR_CATEGORY_LIBLOADORDER: c_uchar = 2;
/// An error from loot-condition-interpreter.
#[unsafe(no_mangle)]
pub static LIBLOOT_SYSTEM_ERROR_CATEGORY_LCI: c_uchar = 3;
mod esplugin;
mod lci;
mod libloadorder;
// It's important for API stability that these variants' values don't change.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(u8)]
#[non_exhaustive]
pub enum SystemErrorCategory {
Esplugin = LIBLOOT_SYSTEM_ERROR_CATEGORY_ESPLUGIN,
Libloadorder = LIBLOOT_SYSTEM_ERROR_CATEGORY_LIBLOADORDER,
LootConditionInterpreter = LIBLOOT_SYSTEM_ERROR_CATEGORY_LCI,
Esplugin = 1,
Libloadorder = 2,
LootConditionInterpreter = 3,
}
impl std::fmt::Display for SystemErrorCategory {
+26 -61
View File
@@ -1,84 +1,49 @@
// Unless otherwise noted, these constants and the mapping logic are copied from
// libloadorder-ffi.
use loadorder::Error;
use std::{ffi::c_int, io::ErrorKind};
/// There is a mismatch between the files used to keep track of load order.
///
/// This warning can only occur when using libloadorder with a game that uses the textfile-based
/// load order system. The load order in the active plugins list file (`plugins.txt`) does not
/// match the load order in the full load order file (`loadorder.txt`). Synchronisation between
/// the two is automatic when load order is managed through libloadorder. It is left to the client
/// to decide how best to restore synchronisation.
#[unsafe(no_mangle)]
pub static LIBLO_WARN_LO_MISMATCH: c_int = 2;
/// The specified file could not be found.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_FILE_NOT_FOUND: c_int = 6;
const LIBLO_ERROR_FILE_NOT_FOUND: c_int = 6;
/// A file could not be renamed.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_FILE_RENAME_FAIL: c_int = 7;
const LIBLO_ERROR_FILE_RENAME_FAIL: c_int = 7;
/// There was an error parsing a plugin file.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_FILE_PARSE_FAIL: c_int = 10;
const LIBLO_ERROR_FILE_PARSE_FAIL: c_int = 10;
/// Invalid arguments were given for the function.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_INVALID_ARGS: c_int = 12;
const LIBLO_ERROR_INVALID_ARGS: c_int = 12;
/// A thread lock was poisoned.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_POISONED_THREAD_LOCK: c_int = 14;
/// An unknown I/O error occurred. This is used when the I/O error kind doesn't fit another error
/// code.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_IO_ERROR: c_int = 15;
/// An unknown I/O error occurred. This is used when the I/O error kind doesn't
/// fit another error code.
const LIBLO_ERROR_IO_ERROR: c_int = 15;
/// Permission denied while trying to access a filesystem path.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_IO_PERMISSION_DENIED: c_int = 16;
const LIBLO_ERROR_IO_PERMISSION_DENIED: c_int = 16;
/// A plugin filename contains characters that do not have Windows-1252 code points, or a character
/// string contains a null character.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_TEXT_ENCODE_FAIL: c_int = 17;
/// A plugin filename contains characters that do not have Windows-1252 code
/// points, or a character string contains a null character.
const LIBLO_ERROR_TEXT_ENCODE_FAIL: c_int = 17;
/// Text expected to be encoded in Windows-1252 could not be decoded to UTF-8.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_TEXT_DECODE_FAIL: c_int = 18;
const LIBLO_ERROR_TEXT_DECODE_FAIL: c_int = 18;
/// The library encountered an error that should not have been possible to encounter.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_INTERNAL_LOGIC_ERROR: c_int = 19;
/// Something panicked.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_PANICKED: c_int = 20;
/// A path cannot be encoded in UTF-8.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_PATH_ENCODE_FAIL: c_int = 21;
/// The library encountered an error that should not have been possible to
/// encounter.
const LIBLO_ERROR_INTERNAL_LOGIC_ERROR: c_int = 19;
/// An unknown operating system error occurred.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_SYSTEM_ERROR: c_int = 22;
const LIBLO_ERROR_SYSTEM_ERROR: c_int = 22;
/// A system path definition (e.g. for local app data on Windows, or $HOME on Linux) could not be
/// found.
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_NO_PATH: c_int = 23;
/// A system path definition (e.g. for local app data on Windows, or $HOME on
/// Linux) could not be found.
const LIBLO_ERROR_NO_PATH: c_int = 23;
/// Matches the value of the highest-numbered return code, aside from `LIBLO_ERROR_UNKNOWN`.
///
/// Provided in case clients wish to incorporate additional return codes in their implementation
/// and desire some method of avoiding value conflicts.
#[unsafe(no_mangle)]
pub static LIBLO_RETURN_MAX: c_int = 23;
#[unsafe(no_mangle)]
pub static LIBLO_ERROR_UNKNOWN: c_int = c_int::MAX;
// This constant is not copied from libloadorder-ffi, but does not conflict with
// any values defined there.
pub(crate) const LIBLO_ERROR_UNKNOWN: c_int = c_int::MAX;
#[expect(
clippy::wildcard_enum_match_arm,
@@ -94,7 +59,7 @@ fn map_io_error(err: &std::io::Error) -> c_int {
}
#[must_use]
pub fn map_error(err: &Error) -> c_int {
pub(crate) fn map_error(err: &Error) -> c_int {
match err {
Error::InvalidPath(_) => LIBLO_ERROR_FILE_NOT_FOUND,
Error::IoError(_, x) => map_io_error(x),