Skip to content

Commit

Permalink
fix: smdk error for missing Smartmodule.toml #4412 (#4413)
Browse files Browse the repository at this point in the history
* fix: consistent SMARTMODULE_TOML const

* fix: smdk error for missing Smartmodule.toml #4412

* fix: wider range error message fix

* fixup: last SMARTMODULE_TOML consistency
  • Loading branch information
digikata authored Feb 25, 2025
1 parent d0c0553 commit 06b7288
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/fluvio-controlplane-metadata/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fluvio-controlplane-metadata"
edition = "2021"
version = "0.30.1"
version = "0.30.2"
authors = ["Fluvio Contributors <team@fluvio.io>"]
description = "Metadata definition for Fluvio control plane"
repository = "https://github.com/infinyon/fluvio"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ impl SmartModuleMetadata {
use std::fs::read_to_string;

let path_ref = path.as_ref();
let file_str: String = read_to_string(path_ref)?;
let file_str: String = read_to_string(path_ref).map_err(|err| {
let dpath = path_ref.display();
IoError::new(
err.kind(),
format!("reading smartmodule metadata file {dpath}, {err}"),
)
})?;
let metadata = toml::from_str(&file_str).map_err(|err| {
IoError::new(
std::io::ErrorKind::InvalidData,
Expand Down
4 changes: 3 additions & 1 deletion crates/smartmodule-development-kit/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ mod test {
use super::CargoSmDependSource;
use super::FLUVIO_SMARTMODULE_REPO;

use crate::SMARTMODULE_TOML;

#[test]
fn test_default_template() {
let template = SmdkTemplate::default().unwrap();
Expand All @@ -568,7 +570,7 @@ mod test {

let mut temp_dir = temp_dir.unwrap();
let smart_toml =
temp_dir.find(|entry| entry.as_ref().unwrap().file_name().eq("SmartModule.toml"));
temp_dir.find(|entry| entry.as_ref().unwrap().file_name().eq(SMARTMODULE_TOML));

assert!(
smart_toml.is_some(),
Expand Down
5 changes: 2 additions & 3 deletions crates/smartmodule-development-kit/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use cargo_builder::package::PackageInfo;

use crate::cmd::PackageCmd;
use crate::ENV_SMDK_NOWASI;

pub const DEFAULT_META_LOCATION: &str = "SmartModule.toml";
use crate::SMARTMODULE_TOML;

/// Load SmartModule into Fluvio cluster
#[derive(Debug, Parser)]
Expand Down Expand Up @@ -56,7 +55,7 @@ impl LoadCmd {
let package_info = PackageInfo::from_options(&opt)?;

// load ./SmartModule.toml relative to the project root
let sm_toml = package_info.package_relative_path(DEFAULT_META_LOCATION);
let sm_toml = package_info.package_relative_path(SMARTMODULE_TOML);
let pkg_metadata = SmartModuleMetadata::from_toml(sm_toml.as_path())?;
println!("Found SmartModule package: {}", pkg_metadata.package.name);

Expand Down
6 changes: 5 additions & 1 deletion crates/smartmodule-development-kit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tracing::debug;
use cmd::SmdkCommand;

pub const ENV_SMDK_NOWASI: &str = "SMDK_NOWASI";
pub const SMARTMODULE_TOML: &str = "SmartModule.toml";

fn main() -> Result<()> {
fluvio_future::subscriber::init_tracer(None);
Expand All @@ -29,5 +30,8 @@ fn main() -> Result<()> {

pub(crate) fn read_bytes_from_path(path: &PathBuf) -> Result<Vec<u8>> {
debug!(path = ?path.display(), "Loading module");
std::fs::read(path).map_err(|err| anyhow::anyhow!("error reading wasm file: {}", err))
std::fs::read(path).map_err(|err| {
let dpath = path.display();
anyhow::anyhow!("reading wasm file {dpath}, {}", err)
})
}
3 changes: 1 addition & 2 deletions crates/smartmodule-development-kit/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ use hubutil::{
};

use crate::ENV_SMDK_NOWASI;
use crate::SMARTMODULE_TOML;
use crate::cmd::PackageCmd;
use crate::hub::set_hubid;

pub const SMARTMODULE_TOML: &str = "SmartModule.toml";

/// Publish SmartModule to SmartModule Hub
#[derive(Debug, Parser)]
pub struct PublishCmd {
Expand Down

0 comments on commit 06b7288

Please sign in to comment.