From e92b479f3426bc7f8cf1be06fff38471fac3d2a0 Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Thu, 16 Nov 2023 15:04:50 -0500 Subject: [PATCH] fix: remind to build before install --- e2e/tests-dfx/install.bash | 7 +++++++ src/dfx/src/lib/operations/canister/install_canister.rs | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/e2e/tests-dfx/install.bash b/e2e/tests-dfx/install.bash index 5511205a07..bd4a4f3d02 100644 --- a/e2e/tests-dfx/install.bash +++ b/e2e/tests-dfx/install.bash @@ -211,3 +211,10 @@ teardown() { assert_command_fail dfx canister install --all --argument '()' assert_contains "error: the argument '--all' cannot be used with '--argument '" } + +@test "remind to build before install" { + dfx_start + dfx canister create --all + assert_command_fail dfx canister install e2e_project_backend + assert_contains "The canister must be built before install. Please run \`dfx build\`." +} diff --git a/src/dfx/src/lib/operations/canister/install_canister.rs b/src/dfx/src/lib/operations/canister/install_canister.rs index c8be2ea47a..1bd13cd42b 100644 --- a/src/dfx/src/lib/operations/canister/install_canister.rs +++ b/src/dfx/src/lib/operations/canister/install_canister.rs @@ -107,9 +107,13 @@ pub async fn install_canister( let wasm_path: PathBuf = if let Some(wasm_override) = wasm_path_override { wasm_override.into() } else { - canister_info + let build_wasm_path = canister_info .map(|info| info.get_build_wasm_path()) - .context("Failed to find wasm")? + .context("Failed to find wasm")?; + if !build_wasm_path.exists() { + bail!("The canister must be built before install. Please run `dfx build`."); + } + build_wasm_path }; let wasm_module = std::fs::read(&wasm_path) .with_context(|| format!("Failed to read {}.", &wasm_path.display()))?;