Skip to content

Commit

Permalink
start-package: give user helpful error if suspect pkg not built
Browse files Browse the repository at this point in the history
  • Loading branch information
nick1udwig committed May 24, 2024
1 parent 43c9e12 commit 1429cb9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kit"
version = "0.5.0"
version = "0.5.1"
edition = "2021"

[build-dependencies]
Expand Down
23 changes: 20 additions & 3 deletions src/start_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use sha2::{Sha256, Digest};
use std::io::{Read, Write};
use std::path::Path;

use color_eyre::{Result, eyre::{eyre, WrapErr}};
use color_eyre::{Result, Section, eyre::{eyre, WrapErr}};
use fs_err as fs;
use serde_json::json;
use tracing::{info, instrument};
use walkdir::WalkDir;
use zip::write::FileOptions;

use kinode_process_lib::kernel_types::Erc721Metadata;
use kinode_process_lib::kernel_types::{Erc721Metadata, PackageManifestEntry};

use crate::{inject_message, KIT_LOG_PATH_DEFAULT};

Expand Down Expand Up @@ -111,6 +111,24 @@ pub async fn execute(package_dir: &Path, url: &str) -> Result<()> {
let package_name = metadata.properties.package_name.as_str();
let publisher = metadata.properties.publisher.as_str();
let pkg_publisher = format!("{}:{}", package_name, publisher);

let manifest: Vec<PackageManifestEntry> =
serde_json::from_reader(fs::File::open(pkg_dir.join("manifest.json"))
.wrap_err_with(|| "Missing required manifest.json file. See discussion at https://book.kinode.org/my_first_app/chapter_1.html?highlight=manifest.json#pkgmanifestjson")?
)?;
let has_all_entries = manifest.iter().fold(true, |has_all_entries, entry| {
let file_path = entry.process_wasm_path
.strip_prefix("/")
.unwrap_or_else(|| &entry.process_wasm_path);
has_all_entries && pkg_dir.join(file_path).exists()
});
if !has_all_entries {
return Err(eyre!(
"Missing a .wasm file declared by manifest.json."
).with_suggestion(|| "Try `kit build`ing package first, or updating manifest.json.")
);
}

info!("{}", pkg_publisher);

// Create zip and put it in /target
Expand All @@ -120,7 +138,6 @@ pub async fn execute(package_dir: &Path, url: &str) -> Result<()> {
let zip_filename = target_dir.join(&pkg_publisher).with_extension("zip");
zip_directory(&pkg_dir, &zip_filename.to_str().unwrap())?;


let mut file = fs::File::open(&zip_filename)?;
let mut hasher = Sha256::new();
let mut buffer = Vec::new();
Expand Down

0 comments on commit 1429cb9

Please sign in to comment.