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

feat: improve python related errors #161

Merged
merged 1 commit into from
Mar 3, 2022
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
14 changes: 7 additions & 7 deletions crates/pathfinder/src/bin/pathfinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ async fn main() -> anyhow::Result<()> {
.init();

let config =
config::Configuration::parse_cmd_line_and_cfg_file().expect("Configuration failed");
config::Configuration::parse_cmd_line_and_cfg_file().context("Parsing configuration")?;

info!("🏁 Starting node.");
let eth_transport = ethereum_transport(config.ethereum)
.await
.context("Create Ethereum transport")?;
.context("Creating Ethereum transport")?;

let network_chain = ethereum::chain(&eth_transport)
.await
.context("Determine Ethereum chain")?;
.context("Determining Ethereum chain")?;

let database_path = match network_chain {
ethereum::Chain::Mainnet => "mainnet.sqlite",
Expand All @@ -54,13 +54,13 @@ async fn main() -> anyhow::Result<()> {
futures::future::pending(),
)
.await
.context("Create python process for call handling")?;
.context("Creating python process for call handling. Have you setup and activate the python `VIRTUAL_ENV` in the `py` directory?")?;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.context("Creating python process for call handling. Have you setup and activate the python `VIRTUAL_ENV` in the `py` directory?")?;
.context("Creating python process for call handling. Have you setup and activated the python `VIRTUAL_ENV` in the `py` directory?")?;


let api =
rpc::api::RpcApi::new(storage, sequencer, network_chain).with_call_handling(call_handle);

let (_rpc_handle, local_addr) =
rpc::run_server(config.http_rpc_addr, api).context("Start the RPC server")?;
rpc::run_server(config.http_rpc_addr, api).context("Starting the RPC server")?;
info!("📡 HTTP-RPC server started on: {}", local_addr);
let () = std::future::pending().await;

Expand All @@ -80,11 +80,11 @@ async fn ethereum_transport(config: EthereumConfig) -> anyhow::Result<Web3<Http>
None => client,
}
.build()
.context("Create HTTP client")?;
.context("Creating HTTP client")?;

let mut url = config.url;
url.set_password(config.password.as_deref())
.map_err(|_| anyhow::anyhow!("Set password"))?;
.map_err(|_| anyhow::anyhow!("Setting password"))?;

let client = Http::with_client(client, url);

Expand Down
6 changes: 3 additions & 3 deletions crates/pathfinder/src/cairo/ext_py/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ pub async fn start(
// good, now we can launch the other processes requested later
},
SubProcessEvent::CommandHandled(..) => {
unreachable!("first message must not be CommandHandled");
unreachable!("First message must not be CommandHandled");
},
}
},
Some(res) = &mut joinhandles.next() => {
match res {
Ok(Ok(t)) => unreachable!("first subprocess should not have exited successfully: {:?}", t),
Ok(Ok(t)) => unreachable!("First subprocess should not have exited successfully: {:?}", t),
// this is the failure to start
Ok(Err(e)) => return Err(e),
// this is the failure to join, panic or cancellation
Err(e) => return Err(e).context("Launch first python executor"),
Err(e) => return Err(e).context("Launching first python executor"),
}
}
};
Expand Down
5 changes: 2 additions & 3 deletions crates/pathfinder/src/cairo/ext_py/sub_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ async fn spawn(
database_path: PathBuf,
) -> anyhow::Result<(Child, u32, ChildStdin, BufReader<ChildStdout>, String)> {
// there is not intentionally any std::fs::exists calls to avoid bringing any TOCTOU issues.
let virtual_env = std::env::var_os("VIRTUAL_ENV")
.context("VIRTUAL_ENV is not defined; has the user activated virtual environment")?;
let virtual_env = std::env::var_os("VIRTUAL_ENV").context("VIRTUAL_ENV is not defined")?;

// FIXME: use choom, add something over /proc/self/oom_score_adj ?
let mut python_exe = PathBuf::from(&virtual_env);
Expand Down Expand Up @@ -246,7 +245,7 @@ async fn spawn(
anyhow::ensure!(
// buffer will contain the newline, which doesn't bother serde_json
buffer.trim() == "ready",
"failed to read ready from python process, read: {buffer:?}"
"Failed to read 'ready' from python process, read: {buffer:?}"
);
buffer.clear();

Expand Down