Skip to content

Commit b18a312

Browse files
committed
fixed bug for files with no extension not being considered binaries when filtering and improved error message for read errors
1 parent 262a689 commit b18a312

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

tmc-langs-framework/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub enum TmcError {
2626
TarFinish(#[source] std::io::Error),
2727
#[error("Failed to read line")]
2828
ReadLine(#[source] std::io::Error),
29+
#[error("Failed to parse file {0}")]
30+
SubmissionParse(PathBuf, #[source] Box<Self>),
2931
#[error("Failed to canonicalize path {0}")]
3032
Canonicalize(PathBuf, #[source] std::io::Error),
3133
#[error("Error occurred in a child process")]

tmc-langs-framework/src/io/submission_processing.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn copy_file(
112112
let extension = file.extension().and_then(|e| e.to_str());
113113
let is_binary = extension
114114
.map(|e| NON_TEXT_TYPES.is_match(e))
115-
.unwrap_or_default();
115+
.unwrap_or(true); // paths with no extension are interpreted to be binary files
116116
if is_binary {
117117
// copy binary files
118118
debug!("copying binary file from {:?} to {:?}", file, dest_path);
@@ -122,7 +122,11 @@ fn copy_file(
122122
let source_file = file_util::open_file(file)?;
123123

124124
let parser = MetaSyntaxParser::new(source_file, extension.unwrap_or_default());
125-
let parsed: Vec<MetaString> = parser.collect::<Result<Vec<_>, _>>()?;
125+
let parse_result: Result<Vec<_>, _> = parser.collect();
126+
let parsed = match parse_result {
127+
Ok(parsed) => parsed,
128+
Err(err) => return Err(TmcError::SubmissionParse(file.to_path_buf(), Box::new(err))),
129+
};
126130

127131
// files that don't pass the filter are skipped
128132
if !file_filter(&parsed) {

0 commit comments

Comments
 (0)