Skip to content

Commit

Permalink
scutiger-lfs: print error messages with trailing newline
Browse files Browse the repository at this point in the history
The syntax production requires a trailing newline on error messages.
Let's make sure that we're always emitting a newline at the end of our
error messages by adding one in `send_error` and to each failure we
manually create.

Signed-off-by: brian m. carlson <[email protected]>
  • Loading branch information
bk2204 committed Oct 26, 2023
1 parent 91442b4 commit f5ba0dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
9 changes: 6 additions & 3 deletions scutiger-lfs/src/bin/git-lfs-transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ mod tests {
let expected: &[u8] = b"000eversion=1
0000000fstatus 200
00010000000fstatus 400
00010040error: not allowed: sha512 is not a permitted hash algorithm0000";
00010041error: not allowed: sha512 is not a permitted hash algorithm
0000";
assert_eq!(result, expected);
}

Expand Down Expand Up @@ -514,7 +515,8 @@ mod tests {
004fce08b837fe0c499d48935175ddce784e8c372d3cfb1c574fe1caff605d4f0626 32 upload
0000000fstatus 200
0000000fstatus 400
000100acerror: corrupt data: expected oid ce08b837fe0c499d48935175ddce784e8c372d3cfb1c574fe1caff605d4f0626, got 367988c7cb91e13beda0a15fb271afcbf02fa7a0e75d9e25ac50b2b4b38af5f50000000fstatus 200
000100aderror: corrupt data: expected oid ce08b837fe0c499d48935175ddce784e8c372d3cfb1c574fe1caff605d4f0626, got 367988c7cb91e13beda0a15fb271afcbf02fa7a0e75d9e25ac50b2b4b38af5f5
0000000fstatus 200
0000000fstatus 404
0001000dnot found0000";
assert_eq!(result, expected);
Expand Down Expand Up @@ -547,7 +549,8 @@ mod tests {
000dpath=foo
0028locked-at=2001-09-17T00:00:00+00:00
0018ownername=test user
0001000cconflict0000000fstatus 200
0001000dconflict
0000000fstatus 200
0001004alock d76670443f4d5ecdeea34c12793917498e18e858c6f74cd38c4b794273bb5e28
004epath d76670443f4d5ecdeea34c12793917498e18e858c6f74cd38c4b794273bb5e28 foo
0069locked-at d76670443f4d5ecdeea34c12793917498e18e858c6f74cd38c4b794273bb5e28 2001-09-17T00:00:00+00:00
Expand Down
17 changes: 9 additions & 8 deletions scutiger-lfs/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<R: io::Read, W: io::Write> PktLineHandler<R, W> {
pub fn send_error(&mut self, status: u32, msg: &str) -> Result<(), Error> {
self.send(format!("status {:03}\n", status).as_bytes())?;
self.delim()?;
self.send(msg.as_bytes())?;
self.send(format!("{}\n", msg).as_bytes())?;
self.flush()?;
Ok(())
}
Expand Down Expand Up @@ -357,7 +357,7 @@ impl<'a, R: io::Read, W: io::Write> Processor<'a, R, W> {
}

fn error(&self, code: u32, msg: &str) -> Result<Status, Error> {
Ok(Status::new_failure(code, msg.as_bytes()))
Ok(Status::new_failure(code, format!("{}\n", msg).as_bytes()))
}

fn read_batch(&mut self, mode: Mode) -> Result<Vec<BatchItem>, Error> {
Expand Down Expand Up @@ -509,7 +509,7 @@ impl<'a, R: io::Read, W: io::Write> Processor<'a, R, W> {
let (rdr, size) = match self.backend.download(&oid, &args) {
Ok(x) => x,
Err(e) if e.io_kind() == io::ErrorKind::NotFound => {
return Ok(Status::new_failure(404, "not found".as_bytes()))
return Ok(Status::new_failure(404, "not found\n".as_bytes()))
}
Err(e) => return Err(e),
};
Expand Down Expand Up @@ -558,7 +558,7 @@ impl<'a, R: io::Read, W: io::Write> Processor<'a, R, W> {
Ok(Status::new_failure_with_args(
409,
lock.as_arguments(),
b"conflict",
b"conflict\n",
))
};
}
Expand Down Expand Up @@ -714,12 +714,13 @@ impl<'a, R: io::Read, W: io::Write> Processor<'a, R, W> {
| ErrorKind::ExtraData
| ErrorKind::CorruptData
| ErrorKind::NotAllowed
| ErrorKind::UnknownCommand => self
.handler
.send_status(Status::new_failure(400, format!("error: {}", e).as_bytes())),
| ErrorKind::UnknownCommand => self.handler.send_status(Status::new_failure(
400,
format!("error: {}\n", e).as_bytes(),
)),
_ => self.handler.send_status(Status::new_failure(
500,
format!("internal error: {}", e).as_bytes(),
format!("internal error: {}\n", e).as_bytes(),
)),
},
}?;
Expand Down

0 comments on commit f5ba0dd

Please sign in to comment.