Skip to content

Commit

Permalink
Fixed Debug impl of EvalOrDeserError printing entire source of fi…
Browse files Browse the repository at this point in the history
…les (#2118)

Now it just prints filenames
  • Loading branch information
rben01 authored Dec 2, 2024
1 parent e474d73 commit 0d93c67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion core/src/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ macro_rules! deserialize_number {
};
}

#[derive(Debug)]
pub enum EvalOrDeserError {
Nickel {
error: error::Error,
Expand All @@ -44,6 +43,21 @@ pub enum EvalOrDeserError {
Deser(RustDeserializationError),
}

impl std::fmt::Debug for EvalOrDeserError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Nickel { error, files } => {
let filenames = files.as_ref().map(|f| f.filenames().collect::<Vec<_>>());
f.debug_struct("Nickel")
.field("error", error)
.field("files", &filenames)
.finish()
}
Self::Deser(arg0) => f.debug_tuple("Deser").field(arg0).finish(),
}
}
}

impl EvalOrDeserError {
fn new<E>(error: E, files: crate::files::Files) -> Self
where
Expand Down
4 changes: 4 additions & 0 deletions core/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ impl Files {
fn get(&self, id: FileId) -> Result<&File, Error> {
self.files.get(id.0 as usize).ok_or(Error::FileMissing)
}

pub(crate) fn filenames(&self) -> impl Iterator<Item = &OsStr> {
self.files.iter().map(|f| &*f.name)
}
}

impl Default for Files {
Expand Down

0 comments on commit 0d93c67

Please sign in to comment.