1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) 2026 Noyalib. All rights reserved.
//! [`ariadne`] adapter for [`crate::Error`].
//!
//! Renders a noyalib error as an [`ariadne::Report`] with the
//! offending byte range labelled, the line/column annotated, and
//! the surrounding source available for terminal-friendly display.
//! Pairs with the existing [`miette::Diagnostic`] impl for users
//! who prefer ariadne's rendering.
//!
//! # Examples
//!
//! ```
//! use noyalib::{from_str, Value};
//! use noyalib::ariadne_adapter::error_to_ariadne_report;
//! use ariadne::Source;
//!
//! let source = "a: [unclosed";
//! let err = from_str::<Value>(source).unwrap_err();
//! let report = error_to_ariadne_report(&err, "input.yaml", source);
//! let mut buf: Vec<u8> = Vec::new();
//! report.write(("input.yaml", Source::from(source)), &mut buf).unwrap();
//! assert!(!buf.is_empty());
//! ```
use crate;
use ;
/// Convert a noyalib [`Error`] into an [`ariadne::Report`].
///
/// `filename` is the source identifier ariadne prints in the
/// report header. `source` is the YAML input — its byte length is
/// used to clamp the highlighted byte range so a stale or trimmed
/// `source` never panics inside ariadne.
///
/// When the error has no location attached (`Error::location()`
/// returns `None`), the resulting report is a header-only message
/// without a source label — matching the existing
/// [`Error::format_with_source`] fallback.
///
/// # Examples
///
/// ```
/// use noyalib::{from_str, Value};
/// use noyalib::ariadne_adapter::error_to_ariadne_report;
/// use ariadne::Source;
///
/// let source = "a: [unclosed";
/// let err = from_str::<Value>(source).unwrap_err();
/// let report = error_to_ariadne_report(&err, "input.yaml", source);
/// let mut out: Vec<u8> = Vec::new();
/// report.write(("input.yaml", Source::from(source)), &mut out).unwrap();
/// assert!(!out.is_empty());
/// ```
/// Compute a sensible byte range for the error's primary label.
///
/// [`Location`] carries a single byte index; ariadne wants a
/// `Range<usize>`. We expand the index to cover the next character
/// (so the caret doesn't render as a zero-width range) and clamp
/// to the source bounds — never panics on a trimmed `source`.