Skip to content

Commit 1bb9edc

Browse files
xvchrisxvchrisematipico
authored
feat(biome_service): include file path in NotFound diagnostic (#9364)
Co-authored-by: xvchris <chrisjh@foxmail.com> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
1 parent 71c7df6 commit 1bb9edc

4 files changed

Lines changed: 34 additions & 23 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#9357](https://github.com/biomejs/biome/issues/9357). Improved the information emitted by some diagnostics.

crates/biome_service/src/diagnostics.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ impl WorkspaceError {
114114
})
115115
}
116116

117-
pub fn not_found() -> Self {
118-
Self::NotFound(NotFound)
117+
pub fn not_found(path: impl Into<String>) -> Self {
118+
Self::NotFound(NotFound { path: path.into() })
119119
}
120120

121121
#[inline]
@@ -257,10 +257,16 @@ pub struct NonUtf8Path {
257257
#[derive(Debug, Serialize, Deserialize, Diagnostic)]
258258
#[diagnostic(
259259
category = "internalError/fs",
260-
message = "The file does not exist in the workspace.",
260+
message(
261+
message("The file "{self.path}" does not exist in the workspace."),
262+
description = "The file {path} does not exist in the workspace."
263+
),
261264
tags(INTERNAL)
262265
)]
263-
pub struct NotFound;
266+
pub struct NotFound {
267+
#[location(resource)]
268+
path: String,
269+
}
264270

265271
#[derive(Debug, Diagnostic, Deserialize, Serialize)]
266272
#[diagnostic(category = "internalError/panic", severity = Fatal, tags(INTERNAL))]
@@ -700,7 +706,7 @@ pub struct ConfigurationOutsideProject;
700706

701707
#[cfg(test)]
702708
mod test {
703-
use crate::diagnostics::{CantReadFile, FileIgnored, NotFound, SourceFileNotSupported};
709+
use crate::diagnostics::{CantReadFile, FileIgnored, SourceFileNotSupported};
704710
use crate::file_handlers::DocumentFileSource;
705711
use crate::{TransportError, WorkspaceError};
706712
use biome_diagnostics::{DiagnosticExt, Error, print_diagnostic_to_string};
@@ -751,7 +757,7 @@ mod test {
751757
fn not_found() {
752758
snap_diagnostic(
753759
"not_found",
754-
WorkspaceError::NotFound(NotFound).with_file_path("not_found.js"),
760+
WorkspaceError::not_found("not_found.js").into(),
755761
)
756762
}
757763

crates/biome_service/src/snapshots/not_found.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ expression: content
44
---
55
not_found.js internalError/fs INTERNAL ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
66

7-
× The file does not exist in the workspace.
7+
× The file not_found.js does not exist in the workspace.
88

99
! This diagnostic was derived from an internal Biome error. Potential bug, please report it if necessary.

crates/biome_service/src/workspace/server.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl WorkspaceServer {
222222
}
223223
}
224224

225-
Err(WorkspaceError::not_found())
225+
Err(WorkspaceError::not_found(path.to_string()))
226226
}
227227

228228
/// Checks whether the directory identified by the given `path` contains a
@@ -624,7 +624,7 @@ impl WorkspaceServer {
624624

625625
match syntax {
626626
Ok(syntax) => match syntax {
627-
None => Err(WorkspaceError::not_found()),
627+
None => Err(WorkspaceError::not_found(path.to_string())),
628628
Some(syntax) => Ok(syntax),
629629
},
630630
Err(FileTooLarge { .. }) => Err(WorkspaceError::file_ignored(path.to_string())),
@@ -642,11 +642,11 @@ impl WorkspaceServer {
642642
.pin()
643643
.get(path)
644644
.cloned()
645-
.ok_or_else(WorkspaceError::not_found)?;
645+
.ok_or_else(|| WorkspaceError::not_found(path.to_string()))?;
646646

647647
match syntax.transpose() {
648648
Ok(syntax) => match syntax {
649-
None => Err(WorkspaceError::not_found()),
649+
None => Err(WorkspaceError::not_found(path.to_string())),
650650
Some(syntax) => Ok((syntax.clone(), services.clone())),
651651
},
652652
Err(FileTooLarge { .. }) => Err(WorkspaceError::file_ignored(path.to_string())),
@@ -660,7 +660,7 @@ impl WorkspaceServer {
660660
self.documents
661661
.pin()
662662
.get(path)
663-
.ok_or_else(WorkspaceError::not_found)
663+
.ok_or_else(|| WorkspaceError::not_found(path.to_string()))
664664
.and_then(|doc| match &doc.syntax {
665665
Some(syntax) => match syntax {
666666
Ok(syntax) => Ok((
@@ -670,7 +670,7 @@ impl WorkspaceServer {
670670
)),
671671
Err(FileTooLarge { .. }) => Err(WorkspaceError::file_ignored(path.to_string())),
672672
},
673-
None => Err(WorkspaceError::not_found()),
673+
None => Err(WorkspaceError::not_found(path.to_string())),
674674
})
675675
}
676676

@@ -681,7 +681,7 @@ impl WorkspaceServer {
681681
self.documents
682682
.pin()
683683
.get(path)
684-
.ok_or_else(WorkspaceError::not_found)
684+
.ok_or_else(|| WorkspaceError::not_found(path.to_string()))
685685
.and_then(|doc| match &doc.syntax {
686686
Some(syntax) => match syntax {
687687
Ok(syntax) => Ok((
@@ -693,7 +693,7 @@ impl WorkspaceServer {
693693
)),
694694
Err(FileTooLarge { .. }) => Err(WorkspaceError::file_ignored(path.to_string())),
695695
},
696-
None => Err(WorkspaceError::not_found()),
696+
None => Err(WorkspaceError::not_found(path.to_string())),
697697
})
698698
}
699699

@@ -736,7 +736,7 @@ impl WorkspaceServer {
736736
) -> Result<ParseResult, WorkspaceError> {
737737
let file_source = self
738738
.get_source(file_source_index)
739-
.ok_or_else(WorkspaceError::not_found)?;
739+
.ok_or_else(|| WorkspaceError::not_found(path.to_string()))?;
740740
let capabilities = self.features.get_capabilities(file_source);
741741

742742
let parse = capabilities
@@ -945,7 +945,7 @@ impl WorkspaceServer {
945945
let package_path = path
946946
.parent()
947947
.map(|parent| parent.to_path_buf())
948-
.ok_or_else(WorkspaceError::not_found)?;
948+
.ok_or_else(|| WorkspaceError::not_found(path.to_string()))?;
949949

950950
match update_kind {
951951
UpdateKind::AddedOrChanged(_, root, _) => {
@@ -960,7 +960,7 @@ impl WorkspaceServer {
960960
let package_path = path
961961
.parent()
962962
.map(|parent| parent.to_path_buf())
963-
.ok_or_else(WorkspaceError::not_found)?;
963+
.ok_or_else(|| WorkspaceError::not_found(path.to_string()))?;
964964

965965
match update_kind {
966966
UpdateKind::AddedOrChanged(_, root, _) => {
@@ -978,7 +978,7 @@ impl WorkspaceServer {
978978
let package_path = path
979979
.parent()
980980
.map(|parent| parent.to_path_buf())
981-
.ok_or_else(WorkspaceError::not_found)?;
981+
.ok_or_else(|| WorkspaceError::not_found(path.to_string()))?;
982982

983983
match update_kind {
984984
UpdateKind::AddedOrChanged(_, root, _) => {
@@ -1506,7 +1506,7 @@ impl Workspace for WorkspaceServer {
15061506
.pin()
15071507
.get(params.path.as_path())
15081508
.map(|document| document.content.clone())
1509-
.ok_or_else(WorkspaceError::not_found)
1509+
.ok_or_else(|| WorkspaceError::not_found(params.path.to_string()))
15101510
}
15111511

15121512
fn check_file_size(
@@ -1515,7 +1515,7 @@ impl Workspace for WorkspaceServer {
15151515
) -> Result<CheckFileSizeResult, WorkspaceError> {
15161516
let documents = self.documents.pin();
15171517
let Some(document) = documents.get(params.path.as_path()) else {
1518-
return Err(WorkspaceError::not_found());
1518+
return Err(WorkspaceError::not_found(params.path.to_string()));
15191519
};
15201520
let file_size = document.content.len();
15211521
let limit = self
@@ -1543,7 +1543,7 @@ impl Workspace for WorkspaceServer {
15431543
let (index, existing_version) = documents
15441544
.get(path.as_path())
15451545
.map(|document| (document.file_source_index, document.version))
1546-
.ok_or_else(WorkspaceError::not_found)?;
1546+
.ok_or_else(|| WorkspaceError::not_found(path.to_string()))?;
15471547

15481548
if existing_version.is_some_and(|existing_version| existing_version >= version) {
15491549
warn!(%version, %path, "outdated_file_change");
@@ -1663,7 +1663,7 @@ impl Workspace for WorkspaceServer {
16631663

16641664
documents
16651665
.insert(path.clone().into(), document)
1666-
.ok_or_else(WorkspaceError::not_found)?;
1666+
.ok_or_else(|| WorkspaceError::not_found(path.to_string()))?;
16671667

16681668
let mut final_diagnostics = vec![];
16691669

0 commit comments

Comments
 (0)