refactor(errors): adopt reportable error terminology

This commit is contained in:
Onur Özkan committed 2026-08-23 00:49:25 +03:00
1 parent 21e9497915
commit 9fec2fa095
92 files changed
+270 -269

No files matched your search

@@ -0,0 +1,8 @@
use kaptan_err_reportable_macros::propagate;
#[propagate(report)]
fn invalid() -> Result<(), ()> {
Ok(())
}
fn main() {}
@@ -0,0 +1,7 @@
error: kaptan_err_reportable::propagate does not accept arguments
--> tests/ui/arguments.rs:3:1
|
3 | #[propagate(report)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `propagate` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -0,0 +1,8 @@
use kaptan_err_reportable_macros::propagate;
#[propagate]
const fn invalid() -> Result<(), ()> {
Ok(())
}
fn main() {}
@@ -0,0 +1,5 @@
error: kaptan_err_reportable::propagate does not support const functions
--> tests/ui/const_fn.rs:4:1
|
4 | const fn invalid() -> Result<(), ()> {
| ^^^^^
@@ -0,0 +1,13 @@
extern crate self as kaptan_err_reportable;
use kaptan_err_reportable_macros::KaptanError;
#[derive(Debug, KaptanError)]
enum DuplicateId {
#[kaptan_error(id = 42)]
First,
#[kaptan_error(id = 42)]
Second,
}
fn main() {}
@@ -0,0 +1,5 @@
error: Kaptan error ID 42 is already assigned to variant First
--> tests/ui/duplicate_id.rs:10:5
|
10 | Second,
| ^^^^^^
@@ -0,0 +1,37 @@
extern crate self as kaptan_err_reportable;
use kaptan_err_reportable_macros::KaptanError;
#[derive(Clone, Copy)]
pub struct ErrorId(u16);
impl ErrorId {
pub const fn new(id: u16) -> Self {
Self(id)
}
pub const fn get(self) -> u16 {
self.0
}
}
pub trait ReportableError {
fn error_id(&self) -> ErrorId;
}
#[derive(Debug, KaptanError)]
enum FirstError {
#[kaptan_error(id = 77)]
Failed,
}
#[derive(Debug, KaptanError)]
enum SecondError {
#[kaptan_error(id = 77)]
Failed,
}
fn main() {
let _ = FirstError::Failed.error_id();
let _ = SecondError::Failed.error_id();
}
@@ -0,0 +1,7 @@
error: symbol `__kaptan_error_id_77` is already defined
--> tests/ui/duplicate_id_across_enums.rs:28:17
|
28 | #[derive(Debug, KaptanError)]
| ^^^^^^^^^^^
|
= note: this error originates in the derive macro `KaptanError` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -0,0 +1,43 @@
extern crate self as kaptan_err_reportable;
use kaptan_err_reportable_macros::KaptanError;
#[derive(Clone, Copy)]
pub struct ErrorId(u16);
impl ErrorId {
pub const fn new(id: u16) -> Self {
Self(id)
}
pub const fn get(self) -> u16 {
self.0
}
}
pub trait ReportableError {
fn error_id(&self) -> ErrorId;
}
#[derive(Debug, KaptanError)]
enum Generic<'a, T>
where
T: Copy,
{
#[kaptan_error(id = 65201)]
Unit,
#[kaptan_error(id = 65202)]
Tuple(T, u8),
#[kaptan_error(id = 65203)]
Named { label: &'a str },
}
fn main() {
fn assert_error<T: core::error::Error>() {}
assert_error::<Generic<'_, u8>>();
assert_eq!(Generic::<u8>::Unit.error_id().get(), 65201);
assert_eq!(Generic::Tuple(1_u8, 2).error_id().get(), 65202);
let named: Generic<'_, u8> = Generic::Named { label: "test" };
assert_eq!(named.error_id().get(), 65203);
assert_eq!(named.to_string(), "65203");
}
@@ -0,0 +1,10 @@
extern crate self as kaptan_err_reportable;
use kaptan_err_reportable_macros::KaptanError;
#[derive(Debug, KaptanError)]
enum MissingId {
Variant,
}
fn main() {}
@@ -0,0 +1,5 @@
error: missing `#[kaptan_error(id = ...)]` on Kaptan error variant
--> tests/ui/missing_id.rs:7:5
|
7 | Variant,
| ^^^^^^^
@@ -0,0 +1,6 @@
use kaptan_err_reportable_macros::propagate;
#[propagate]
fn invalid() {}
fn main() {}
@@ -0,0 +1,7 @@
error: kaptan_err_reportable::propagate requires an explicit Result<T, E> return type
--> tests/ui/missing_return.rs:3:1
|
3 | #[propagate]
| ^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `propagate` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -0,0 +1,18 @@
use kaptan_err_reportable_macros::propagate;
extern crate self as kaptan_err_reportable;
pub trait ReportableError {}
pub mod __private {
pub fn report_result<T, E: crate::ReportableError>(_: &Result<T, E>, _: &'static str) {}
}
struct PlainError;
#[propagate]
fn invalid() -> Result<(), PlainError> {
Err(PlainError)
}
fn main() {}
@@ -0,0 +1,17 @@
error[E0277]: the trait bound `PlainError: ReportableError` is not satisfied
--> tests/ui/no_error_report.rs:13:1
|
13 | #[propagate]
| ^^^^^^^^^^^^ the trait `ReportableError` is not implemented for `PlainError`
|
help: this trait has no implementations, consider adding one
--> tests/ui/no_error_report.rs:5:1
|
5 | pub trait ReportableError {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `report_result`
--> tests/ui/no_error_report.rs:8:32
|
8 | pub fn report_result<T, E: crate::ReportableError>(_: &Result<T, E>, _: &'static str) {}
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `report_result`
= note: this error originates in the attribute macro `propagate` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -0,0 +1,14 @@
use kaptan_err_reportable_macros::propagate;
extern crate self as kaptan_err_reportable;
pub mod __private {
pub fn report_result<T, E>(_: &Result<T, E>, _: &'static str) {}
}
#[propagate]
fn invalid() -> bool {
true
}
fn main() {}
@@ -0,0 +1,17 @@
error[E0308]: mismatched types
--> tests/ui/non_result.rs:9:1
|
9 | #[propagate]
| ^^^^^^^^^^^^
| |
| expected `&Result<_, _>`, found `&bool`
| arguments to this function are incorrect
|
= note: expected reference `&Result<_, _>`
found reference `&bool`
note: function defined here
--> tests/ui/non_result.rs:6:12
|
6 | pub fn report_result<T, E>(_: &Result<T, E>, _: &'static str) {}
| ^^^^^^^^^^^^^ ----------------
= note: this error originates in the attribute macro `propagate` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -0,0 +1,8 @@
use kaptan_err_reportable_macros::KaptanError;
#[derive(KaptanError)]
struct NotAnError {
code: u8,
}
fn main() {}
@@ -0,0 +1,5 @@
error: KaptanError can only be derived for enums, not structs
--> tests/ui/struct.rs:4:8
|
4 | struct NotAnError {
| ^^^^^^^^^^
@@ -0,0 +1,8 @@
use kaptan_err_reportable_macros::KaptanError;
#[derive(KaptanError)]
union NotAnError {
code: u8,
}
fn main() {}
@@ -0,0 +1,5 @@
error: KaptanError can only be derived for enums, not unions
--> tests/ui/union.rs:4:7
|
4 | union NotAnError {
| ^^^^^^^^^^
@@ -0,0 +1,8 @@
use kaptan_err_reportable_macros::propagate;
#[propagate]
unsafe fn invalid() -> Result<(), ()> {
Ok(())
}
fn main() {}
@@ -0,0 +1,5 @@
error: kaptan_err_reportable::propagate does not support unsafe functions
--> tests/ui/unsafe_fn.rs:4:1
|
4 | unsafe fn invalid() -> Result<(), ()> {
| ^^^^^^
@@ -0,0 +1,11 @@
extern crate self as kaptan_err_reportable;
use kaptan_err_reportable_macros::KaptanError;
#[derive(Debug, KaptanError)]
enum ZeroId {
#[kaptan_error(id = 0)]
Variant,
}
fn main() {}
@@ -0,0 +1,5 @@
error: Kaptan error ID zero is reserved
--> tests/ui/zero_id.rs:7:25
|
7 | #[kaptan_error(id = 0)]
| ^