Skip to content

Commit 966c118

Browse files
chore: better error messages
1 parent c68c941 commit 966c118

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

crates/turborepo-lib/src/config/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ pub enum Error {
211211
#[source_code]
212212
text: NamedSource<String>,
213213
},
214+
#[error("\"$TURBO_ROOT$\" must be followed by a '/'.")]
215+
InvalidTurboRootNeedsSlash {
216+
#[label("\"$TURBO_ROOT$\" must be followed by a '/'.")]
217+
span: Option<SourceSpan>,
218+
#[source_code]
219+
text: NamedSource<String>,
220+
},
214221
}
215222

216223
const DEFAULT_API_URL: &str = "https://vercel.com/api";

crates/turborepo-lib/src/turbo_json/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub use loader::TurboJsonLoader;
3434
use crate::{boundaries::BoundariesConfig, config::UnnecessaryPackageTaskSyntaxError};
3535

3636
const TURBO_ROOT: &str = "$TURBO_ROOT$";
37+
const TURBO_ROOT_SLASH: &str = "$TURBO_ROOT$/";
3738

3839
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Clone, Deserializable)]
3940
#[serde(rename_all = "camelCase")]
@@ -777,7 +778,14 @@ fn replace_turbo_root_token_in_string(
777778
input: &mut Spanned<UnescapedString>,
778779
path_to_repo_root: &RelativeUnixPath,
779780
) -> Result<(), Error> {
780-
match input.find(TURBO_ROOT) {
781+
let turbo_root_index = input.find(TURBO_ROOT);
782+
if let Some(index) = turbo_root_index {
783+
if !input.as_inner()[index..].starts_with(TURBO_ROOT_SLASH) {
784+
let (span, text) = input.span_and_text("turbo.json");
785+
return Err(Error::InvalidTurboRootNeedsSlash { span, text });
786+
}
787+
}
788+
match turbo_root_index {
781789
Some(0) => {
782790
// Replace
783791
input
@@ -1283,7 +1291,8 @@ mod tests {
12831291
#[test_case("index.ts", Ok("index.ts") ; "no token")]
12841292
#[test_case("$TURBO_ROOT$/config.txt", Ok("../../config.txt") ; "valid token")]
12851293
#[test_case("!$TURBO_ROOT$/README.md", Ok("!../../README.md") ; "negation")]
1286-
#[test_case("../$TURBO_ROOT$/config.txt", Err("Cannot use '$TURBO_ROOT$' anywhere besides start of string.") ; "invalid token")]
1294+
#[test_case("../$TURBO_ROOT$/config.txt", Err("\"$TURBO_ROOT$\" must be used at the start of glob.") ; "invalid token")]
1295+
#[test_case("$TURBO_ROOT$config.txt", Err("\"$TURBO_ROOT$\" must be followed by a '/'.") ; "trailing slash")]
12871296
fn test_replace_turbo_root(input: &'static str, expected: Result<&str, &str>) {
12881297
let mut spanned_string = Spanned::new(UnescapedString::from(input))
12891298
.with_path(Arc::from("turbo.json"))

0 commit comments

Comments
 (0)