Skip to content

Commit

Permalink
Merge pull request #204 from NethermindEth/feat/filenotfound-fix
Browse files Browse the repository at this point in the history
Fixed error processing for new cairo file
  • Loading branch information
rjnrohit authored Nov 14, 2023
2 parents 77ea748 + 7d6d588 commit 37906cc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
3 changes: 1 addition & 2 deletions api/src/handlers/compile_casm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use rocket::tokio::fs;
use rocket::State;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use tracing::info;
use tracing::instrument;
use tracing::{debug, info, instrument};

#[instrument]
#[get("/compile-to-casm/<version>/<remix_file_path..>")]
Expand Down
45 changes: 29 additions & 16 deletions api/src/handlers/compile_sierra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,7 @@ pub async fn do_compile_to_sierra(
.wait_with_output()
.map_err(ApiError::FailedToReadOutput)?;

let file_content = fs::read_to_string(
NamedFile::open(&sierra_path)
.await
.map_err(ApiError::FailedToReadFile)?
.path()
.to_str()
.ok_or(ApiError::FailedToParseString)?,
)
.await
.map_err(ApiError::FailedToReadFile)?;
// Process the output messages

let message = String::from_utf8(output.stderr)
.map_err(ApiError::UTF8Error)?
Expand All @@ -173,10 +164,32 @@ pub async fn do_compile_to_sierra(
}
.to_string();

Ok(Json(CompileResponse {
file_content,
message,
status,
cairo_version,
}))
// Prepare response based on the compilation result
match output.status.code() {
Some(0) => {
let file_content = fs::read_to_string(
NamedFile::open(&sierra_path)
.await
.map_err(ApiError::FailedToReadFile)?
.path()
.to_str()
.ok_or(ApiError::FailedToParseString)?,
)
.await
.map_err(ApiError::FailedToReadFile)?;

Ok(Json(CompileResponse {
file_content,
message,
status,
cairo_version,
}))
}
_ => Ok(Json(CompileResponse {
file_content: String::from(""),
message,
status,
cairo_version,
})),
}
}
2 changes: 1 addition & 1 deletion api/src/handlers/scarb_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rocket::serde::json::Json;
use rocket::State;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use tracing::{info, instrument};
use tracing::{debug, info, instrument};

#[instrument]
#[get("/compile-scarb/<remix_file_path..>")]
Expand Down
2 changes: 1 addition & 1 deletion api/src/handlers/scarb_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rocket::serde::json::Json;
use rocket::State;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use tracing::{info, instrument};
use tracing::{debug, info, instrument};

#[instrument]
#[get("/scarb-test-async/<remix_file_path..>")]
Expand Down

0 comments on commit 37906cc

Please sign in to comment.