Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@

**Fixes**:

- `prqlc fmt` on a file without a `.prql` extension, or a directory with no
`.prql` files, reports that no `.prql` files were found. It previously exited
successfully without formatting anything. `lex`, `debug annotate` and
`experimental highlight` report the same rather than claiming to have found
multiple sources. (@prql-bot, #6587)
- `sql.mysql` compiles a milliseconds interval such as `5milliseconds` to
`INTERVAL 5000 MICROSECOND`, since MySQL has no `MILLISECOND` unit, and
`sql.postgres` compiles a timestamp or time with an offset or `Z` to
Expand Down
5 changes: 5 additions & 0 deletions prqlc/prqlc/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,11 @@ fn read_files(input: &mut clio::ClioPath) -> Result<SourceTree> {

sources.insert(path, file_contents);
}
if sources.is_empty() {
let error =
prqlc::Error::new_simple(format!("No `.prql` files found in `{}`", root.display()));
return Err(prqlc::ErrorMessages::from(error).into());
}
Ok(SourceTree::new(sources, Some(root.to_path_buf())))
}

Expand Down
31 changes: 30 additions & 1 deletion prqlc/prqlc/src/cli/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,36 @@ fn compile_no_prql_files() {
----- stdout -----

----- stderr -----
Error: No `.prql` files found in the source tree
Error: No `.prql` files found in `README.md`
");
}

#[test]
fn no_prql_files() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let txt = temp_dir.path().join("query.txt");
std::fs::write(&txt, "from tracks\n").unwrap();

// `fmt` previously exited successfully without touching the file
assert_cmd_snapshot!(prqlc_command().args(["fmt", "query.txt"]).current_dir(temp_dir.path()), @"
success: false
exit_code: 1
----- stdout -----

----- stderr -----
Error: No `.prql` files found in `query.txt`
");
assert_eq!(std::fs::read_to_string(&txt).unwrap(), "from tracks\n");

// `lex` previously reported finding multiple sources
std::fs::create_dir(temp_dir.path().join("empty")).unwrap();
assert_cmd_snapshot!(prqlc_command().args(["lex", "empty"]).current_dir(temp_dir.path()), @"
success: false
exit_code: 1
----- stdout -----

----- stderr -----
Error: No `.prql` files found in `empty`
");
}

Expand Down
Loading