microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bb481c14648739fdfd94e1f49109610f7d0daecc

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

compiler/qsc/src/error.rs

69lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use miette::Diagnostic;
5use std::{
6 error::Error,
7 fmt::{self, Debug, Display, Formatter},
8};
9use thiserror::Error;
10
11#[derive(Clone, Debug, Error)]
12pub struct WithStack<E>
13where
14 E: Diagnostic + Error,
15{
16 error: E,
17 stack_trace: Option<String>,
18}
19
20impl<E: Diagnostic> WithStack<E> {
21 pub(super) fn new(error: E, stack_trace: Option<String>) -> Self {
22 WithStack { error, stack_trace }
23 }
24
25 pub(super) fn stack_trace(&self) -> &Option<String> {
26 &self.stack_trace
27 }
28}
29
30impl<E: Display + Diagnostic> Display for WithStack<E> {
31 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
32 std::fmt::Display::fmt(&self.error, f)
33 }
34}
35
36// #[diagnostic(transparent)] does not seem to work with generics
37impl<E: Diagnostic> Diagnostic for WithStack<E> {
38 fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
39 self.error.code()
40 }
41
42 fn severity(&self) -> Option<miette::Severity> {
43 self.error.severity()
44 }
45
46 fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
47 self.error.help()
48 }
49
50 fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
51 self.error.url()
52 }
53
54 fn source_code(&self) -> Option<&dyn miette::SourceCode> {
55 self.error.source_code()
56 }
57
58 fn labels(&self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
59 self.error.labels()
60 }
61
62 fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
63 self.error.related()
64 }
65
66 fn diagnostic_source(&self) -> Option<&dyn Diagnostic> {
67 self.error.diagnostic_source()
68 }
69}