Skip to content
Merged
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
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
workflow_dispatch:

Expand All @@ -14,15 +14,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy


- name: Check formatting
run: cargo fmt --all -- --check

- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings

4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ httparse = "1.10.1"
iowrap = "0.2.1"
log = "0.4.27"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
serde_json = "1.0.141"

# We use `opt-level = "s"` as it significantly reduces binary size.
[profile.release]
Expand Down
3 changes: 2 additions & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[toolchain]
channel = "stable"
channel = "1.88.0"
components = ["rustfmt", "clippy"]
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn main() -> std::io::Result<()> {
let listen_port = config.server.listen_port;
let worker_threads = config.server.worker_threads;

log::info!("Listening on {}:{}", listen_addr, listen_port,);
log::info!("Listening on {listen_addr}:{listen_port}",);

HttpServer::new(move || {
App::new()
Expand Down Expand Up @@ -115,7 +115,7 @@ fn prepare_config(env: &environment::Environment) -> config::Config {
Ok(config) => config,

Err(err) => {
log::error!("Failed to build config: {}", err);
log::error!("Failed to build config: {err}");
process::exit(1)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rce_engine/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn prepare_json_response<T: serde::Serialize>(
status_code: 500,
body: ErrorBody {
error: "response.serialize".to_string(),
message: format!("Failed to serialize response: {}", err),
message: format!("Failed to serialize response: {err}"),
},
}),
}
Expand Down
4 changes: 2 additions & 2 deletions src/rce_engine/api/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::UnixStream(err) => {
write!(f, "Unix socket failure: {}", err)
write!(f, "Unix socket failure: {err}")
}

Error::Version(err) => {
write!(f, "Failed to get docker version: {}", err)
write!(f, "Failed to get docker version: {err}")
}
}
}
Expand Down
29 changes: 13 additions & 16 deletions src/rce_engine/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::PrepareRequest(err) => {
write!(f, "Failed to prepare request: {}", err)
write!(f, "Failed to prepare request: {err}")
}

Error::SendRequest(err) => {
write!(f, "Failed while sending request: {}", err)
write!(f, "Failed while sending request: {err}")
}
}
}
Expand All @@ -74,11 +74,11 @@ impl fmt::Display for PrepareRequestError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
PrepareRequestError::SerializeBody(err) => {
write!(f, "Failed to serialize request body: {}", err)
write!(f, "Failed to serialize request body: {err}")
}

PrepareRequestError::Request(err) => {
write!(f, "{}", err)
write!(f, "{err}")
}
}
}
Expand Down Expand Up @@ -167,7 +167,7 @@ pub fn create_container<Stream: Read + Write>(
pub fn start_container_request(
container_id: &str,
) -> Result<http::Request<http_extra::Body>, http::Error> {
let url = format!("/containers/{}/start", container_id);
let url = format!("/containers/{container_id}/start");

http::Request::post(url)
.header("Accept", "application/json")
Expand All @@ -189,7 +189,7 @@ pub fn start_container<Stream: Read + Write>(
pub fn remove_container_request(
container_id: &str,
) -> Result<http::Request<http_extra::Body>, http::Error> {
let url = format!("/containers/{}?v=1&force=1", container_id);
let url = format!("/containers/{container_id}?v=1&force=1");

http::Request::delete(url)
.header("Accept", "application/json")
Expand All @@ -211,10 +211,7 @@ pub fn remove_container<Stream: Read + Write>(
pub fn attach_container_request(
container_id: &str,
) -> Result<http::Request<http_extra::Body>, http::Error> {
let url = format!(
"/containers/{}/attach?stream=1&stdout=1&stdin=1&stderr=1",
container_id
);
let url = format!("/containers/{container_id}/attach?stream=1&stdout=1&stdin=1&stderr=1");

http::Request::post(url)
.header("Host", "127.0.0.1")
Expand Down Expand Up @@ -246,31 +243,31 @@ impl fmt::Display for StreamError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
StreamError::Read(err) => {
write!(f, "{}", err)
write!(f, "{err}")
}

StreamError::ReadStreamType(err) => {
write!(f, "Failed to read stream type: {}", err)
write!(f, "Failed to read stream type: {err}")
}

StreamError::UnknownStreamType(stream_type) => {
write!(f, "Unknown stream type: (type: {})", stream_type)
write!(f, "Unknown stream type: (type: {stream_type})")
}

StreamError::ReadStreamLength(err) => {
write!(f, "Failed to read stream length: {}", err)
write!(f, "Failed to read stream length: {err}")
}

StreamError::InvalidStreamLength(err) => {
write!(f, "Failed to parse stream length: {}", err)
write!(f, "Failed to parse stream length: {err}")
}

StreamError::MaxExecutionTime() => {
write!(f, "Max execution time exceeded")
}

StreamError::MaxReadSize(max_size) => {
write!(f, "Max output size exceeded ({} bytes)", max_size)
write!(f, "Max output size exceeded ({max_size} bytes)")
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/rce_engine/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ pub enum Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::KeyNotFound(key) => write!(f, "Environment key not found: «{0}»", key),
Error::KeyNotFound(key) => write!(f, "Environment key not found: «{key}»"),

Error::Parse { key, details } => write!(
f,
"Failed to parse value for environment key: «{0}», details: {1}",
key, details
"Failed to parse value for environment key: «{key}», details: {details}"
),
}
}
Expand Down
38 changes: 19 additions & 19 deletions src/rce_engine/http_extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,33 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::WriteRequest(err) => {
write!(f, "Failed to send request: {}", err)
write!(f, "Failed to send request: {err}")
}

Error::ReadResponse(err) => {
write!(f, "Failed read response: {}", err)
write!(f, "Failed read response: {err}")
}

Error::ParseResponseHead(err) => {
write!(f, "Failed parse response head: {}", err)
write!(f, "Failed parse response head: {err}")
}

Error::ReadChunkedBody(err) => {
write!(f, "Failed read to chunked response body: {}", err)
write!(f, "Failed read to chunked response body: {err}")
}

Error::ReadBody(err) => {
write!(f, "Failed read to response body: {}", err)
write!(f, "Failed read to response body: {err}")
}

Error::BadStatus(status_code, body) => {
let msg = String::from_utf8(body.to_vec()).unwrap_or(format!("{:?}", body));
let msg = String::from_utf8(body.to_vec()).unwrap_or(format!("{body:?}"));

write!(f, "Unexpected status code {}: {}", status_code, msg)
write!(f, "Unexpected status code {status_code}: {msg}")
}

Error::DeserializeBody(err) => {
write!(f, "Failed deserialize response body: {}", err)
write!(f, "Failed deserialize response body: {err}")
}
}
}
Expand Down Expand Up @@ -134,19 +134,19 @@ impl fmt::Display for ReadChunkError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ReadChunkError::ReadChunkLength(err) => {
write!(f, "Failed to read chunk length: {}", err)
write!(f, "Failed to read chunk length: {err}")
}

ReadChunkError::ParseChunkLength(err) => {
write!(f, "Failed parse chunk length: {}", err)
write!(f, "Failed parse chunk length: {err}")
}

ReadChunkError::ReadChunk(err) => {
write!(f, "Failed read chunk: {}", err)
write!(f, "Failed read chunk: {err}")
}

ReadChunkError::SkipLineFeed(err) => {
write!(f, "Failed read line feed at end of chunk: {}", err)
write!(f, "Failed read line feed at end of chunk: {err}")
}
}
}
Expand Down Expand Up @@ -251,10 +251,10 @@ pub fn format_request_headers<T>(req: &Request<T>) -> String {

fn write_request_head<T, W: Write>(mut writer: W, req: &Request<T>) -> Result<(), io::Error> {
let request_line = format_request_line(req);
write!(writer, "{}\r\n", request_line)?;
write!(writer, "{request_line}\r\n")?;

let headers = format_request_headers(req);
write!(writer, "{}\r\n\r\n", headers)
write!(writer, "{headers}\r\n\r\n")
}

fn write_request_body<W: Write>(mut writer: W, req: &Request<Body>) -> Result<(), io::Error> {
Expand Down Expand Up @@ -291,7 +291,7 @@ impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseError::Parse(err) => {
write!(f, "{}", err)
write!(f, "{err}")
}

ParseError::Empty() => {
Expand All @@ -303,7 +303,7 @@ impl fmt::Display for ParseError {
}

ParseError::Response(err) => {
write!(f, "Invalid response: {}", err)
write!(f, "Invalid response: {err}")
}
}
}
Expand Down Expand Up @@ -348,19 +348,19 @@ impl fmt::Display for ResponseError {
}

ResponseError::HeaderName(err) => {
write!(f, "Invalid header name: {}", err)
write!(f, "Invalid header name: {err}")
}

ResponseError::HeaderValue(err) => {
write!(f, "Invalid header value: {}", err)
write!(f, "Invalid header value: {err}")
}

ResponseError::StatusCode() => {
write!(f, "Failed to parse status code")
}

ResponseError::Builder(err) => {
write!(f, "Response builder error: {}", err)
write!(f, "Response builder error: {err}")
}
}
}
Expand Down
28 changes: 12 additions & 16 deletions src/rce_engine/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn run<T: Serialize>(
Ok(_) => {}

Err(err) => {
log::error!("Failed to remove container: {}", err);
log::error!("Failed to remove container: {err}");
}
}

Expand Down Expand Up @@ -197,47 +197,43 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::UnixStream(err) => {
write!(f, "Unix socket failure: {}", err)
write!(f, "Unix socket failure: {err}")
}

Error::CreateContainer(err) => {
write!(f, "Failed to create container: {}", err)
write!(f, "Failed to create container: {err}")
}

Error::StartContainer(err) => {
write!(f, "Failed to start container: {}", err)
write!(f, "Failed to start container: {err}")
}

Error::AttachContainer(err) => {
write!(f, "Failed to attach to container: {}", err)
write!(f, "Failed to attach to container: {err}")
}

Error::SerializePayload(err) => {
write!(f, "Failed to send payload to stream: {}", err)
write!(f, "Failed to send payload to stream: {err}")
}

Error::ReadStream(err) => {
write!(f, "Failed while reading stream: {}", err)
write!(f, "Failed while reading stream: {err}")
}

Error::StreamStdinUnexpected(bytes) => {
let msg = String::from_utf8(bytes.to_vec()).unwrap_or(format!("{:?}", bytes));
let msg = String::from_utf8(bytes.to_vec()).unwrap_or(format!("{bytes:?}"));

write!(f, "Code runner returned unexpected stdin data: {}", msg)
write!(f, "Code runner returned unexpected stdin data: {msg}")
}

Error::StreamStderr(bytes) => {
let msg = String::from_utf8(bytes.to_vec()).unwrap_or(format!("{:?}", bytes));
let msg = String::from_utf8(bytes.to_vec()).unwrap_or(format!("{bytes:?}"));

write!(f, "Code runner failed with the following message: {}", msg)
write!(f, "Code runner failed with the following message: {msg}")
}

Error::StreamStdoutDecode(err) => {
write!(
f,
"Failed to decode json returned from code runner: {}",
err
)
write!(f, "Failed to decode json returned from code runner: {err}")
}
}
}
Expand Down
Loading