Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better file errors + common import import #235

Merged
merged 2 commits into from
May 17, 2024
Merged
Changes from 1 commit
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
19 changes: 16 additions & 3 deletions src/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,15 @@ fn concat_files<P: AsRef<Path>>(paths: &Vec<P>) -> std::io::Result<String> {
for path in paths {
buf.push_str(
&std::fs::read_to_string(path)
.map_err(|_| {
.map_err(|e| {
panic!(
"can't read: {}",
path.as_ref().to_str().unwrap_or("Path is not in unicode")
"can't read: {}. Err: {:?} | {:?}",
path.as_ref().to_str().unwrap_or("Path is not in unicode"),
e,
paths
.iter()
.map(|p| p.as_ref().to_str().unwrap())
.collect::<Vec<_>>(),
)
})
.unwrap(),
Expand Down Expand Up @@ -918,6 +923,11 @@ impl GenerationScope {
for (scope, content) in self.serialize_scopes.iter_mut() {
content
.push_import("super", "*", None)
.push_import(
format!("{}::serialization", cli.common_import_rust()),
"*",
None,
)
.push_import("std::io", "BufRead", None)
.push_import("std::io", "Seek", None)
.push_import("std::io", "SeekFrom", None)
Expand Down Expand Up @@ -1028,6 +1038,9 @@ impl GenerationScope {
export_raw_bytes_encoding_trait: bool,
cli: &Cli,
) -> std::io::Result<()> {
// check it exists here to get clearer error message
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is checked all the time instead of just when it's overridden as we still pull out the Cargo.toml files from here regardless.

assert!(std::path::Path::exists(&cli.static_dir));

// package.json / scripts
let rust_dir = if cli.package_json {
if cli.json_schema_export {
Expand Down
Loading