Backtrace api and #[from]
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
Línea de trabajo
Ejecuta el Rust playground enlazado y compara las dos variantes del enum usando los puntos de entrada backtrace() y source() que se muestran en el ejemplo. Sigue cómo el comportamiento derivado de thiserror trata #[from] y un Backtrace explícito, y determina y documenta la precedencia prevista; se considera terminado cuando el comportamiento se haya resuelto de forma coherente o se haya confirmado explícitamente como esperado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi,
I discovered a little strange behavior when using the experimental backtrace api together with thiserror.
I have prepared an example gist and the playground
You get different behavior when trying to access the backtrace of an error behind an enum.
When the enum value is derived with from , without specifying an own backtrace member (as tuple)
the backtrace() api call from the Error trait will return None
When the enum value has an own backtrace member, the backtrace() api call will return the backtrace of the underlying error.
Accessing the backtrace value of the enum value is not possible anymore.
From my POV the best way would be that the backtrace() api call should always return the uppermost backtrace if it is specified. Because it would be still possible to use the source() api call to get to the inner error.
Is the current behavior a bug or expected ?
Thanks,
Peter
Putting the code example here as reference also:
#![feature(backtrace)]
#![feature(backtrace_frames)]
use std::{backtrace::Backtrace, error::Error};
use thiserror::Error as ThisError;
#[derive(ThisError, Debug)]
#[error("MyError")]
struct MyError {
backtrace: std::backtrace::Backtrace,
}
#[derive(ThisError, Debug)]
#[error("OtherError")]
struct OtherError {
backtrace: std::backtrace::Backtrace,
}
#[derive(ThisError, Debug)]
enum AllErrors {
#[error("E")]
E(#[from] MyError),
#[error("O")]
O(#[from] OtherError, Backtrace),
}
fn main() {
let my = MyError {
backtrace: std::backtrace::Backtrace::capture(), // Backtrace location A
};
assert!(my.backtrace().is_some());
let other = OtherError {
backtrace: std::backtrace::Backtrace::capture(), // Backtrace location B
};
assert!(other.backtrace().is_some());
let all_my = AllErrors::from(my);
let all_other = AllErrors::from(other); // Implicit Backtrace C
println!("My my {:#?}", all_my.backtrace()); // -> None
println!("My my source {:#?}", all_my.source().unwrap().backtrace()); // -> Backtrace A
println!("Other my {:#?}", all_other.backtrace()); // -> Backtrace B
println!(
"Other my source {:#?}",
all_other.source().unwrap().backtrace() // Backtrace B
);
// Inconsistency:
// Option 1 : Always return inner backtrace
// all_my.backtrace() should return Backtrace A
// all_other.backtrace() should return Backtrace B // as
// Option 2: Always deliver own backtrace
// all_my.backtrace() should return None
// all_other.backtrace() should return Backtrace C ( where all_other was created )
// The prefered option is Option 2 as currently there is no way to access backtrace C
// using the backtrace interface
}
- Lenguaje dominante
- Rust
- Estrellas
- 5.6k
- Forks
- 220
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dtolnay/thiserror
-
Improve #[from] documentation example.Posiblemente ocupada @SatvikMishra08 la tomó hace 50 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
-
No `unused field` warnings are produced on enums deriving thiserror::ErrorPosiblemente ocupada @usmanovbf la tomó hace 240 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
Todos los issues de dtolnay/thiserror
Issues similares
-
Selected chart highlights only its values, not its series names and category labelsPosiblemente ocupada @Higgs32584 la tomó hoy. Abiertobug priority: low ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
storytold/gridcraft#4390 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
bug bugfix priority: medium
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
quarto-dev/q2#1219 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100