diff --git a/e2e/tests-dfx/build_granular.bash b/e2e/tests-dfx/build_granular.bash index 04101028c8..d60b824b53 100644 --- a/e2e/tests-dfx/build_granular.bash +++ b/e2e/tests-dfx/build_granular.bash @@ -47,7 +47,7 @@ teardown() { dfx build e2e_project_backend # validate assets canister wasn't built and can't be installed assert_command_fail dfx canister install e2e_project_frontend - assert_match "No such file or directory" + assert_match "The canister must be built before install. Please run \`dfx build\`." } 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()))?;