Repository: candlecorp/wick (language: rust)

Issue:
The source file in error messages is missing the filename
**Describe the bug**
When a configuration is invalid, the error message is supposed to report the filename of the offending config, but it only reports the containing directory.

**To Reproduce**
Run `wick run app.wick` on an empty `app.wick`

**Expected behavior**
A clear error message reporting an error in `app.wick`

**Actual behavior**
An error message reporting the error comes from the directory `app.wick` is in.

**Environment:**
 - OS: Mac
 - Architecture: m1
 - Build Version: git



Discussion / hints:

Fix patch:
diff --git a/crates/wick/wick-config/src/config/app_config.rs b/crates/wick/wick-config/src/config/app_config.rs
index 382d7bc10..0d3c1bfa1 100644
--- a/crates/wick/wick-config/src/config/app_config.rs
+++ b/crates/wick/wick-config/src/config/app_config.rs
@@ -106,18 +106,13 @@ impl AppConfiguration {
 
   /// Set the source location of the configuration.
   pub fn set_source(&mut self, source: &Path) {
-    // Source is a file, so our baseurl needs to be the parent directory.
-    // Remove the trailing filename from source.
-    if source.is_dir() {
-      self.set_baseurl(source);
-      self.source = Some(source.to_path_buf());
-    } else {
-      let mut s = source.to_path_buf();
-      s.pop();
-
-      self.set_baseurl(&s);
-      self.source = Some(s);
+    let mut source = source.to_path_buf();
+    self.source = Some(source.clone());
+    // Source is (should be) a file, so pop the filename before setting the baseurl.
+    if !source.is_dir() {
+      source.pop();
     }
+    self.set_baseurl(&source);
   }
 
   /// Return the version of the application.
diff --git a/crates/wick/wick-config/src/config/component_config.rs b/crates/wick/wick-config/src/config/component_config.rs
index 24d16c8a3..c6d68e049 100644
--- a/crates/wick/wick-config/src/config/component_config.rs
+++ b/crates/wick/wick-config/src/config/component_config.rs
@@ -114,18 +114,13 @@ impl ComponentConfiguration {
 
   /// Set the source location of the configuration.
   pub fn set_source(&mut self, source: &Path) {
-    // Source is a file, so our baseurl needs to be the parent directory.
-    // Remove the trailing filename from source.
-    if source.is_dir() {
-      self.set_baseurl(source);
-      self.source = Some(source.to_path_buf());
-    } else {
-      let mut s = source.to_path_buf();
-      s.pop();
-
-      self.set_baseurl(&s);
-      self.source = Some(s);
+    let mut source = source.to_path_buf();
+    self.source = Some(source.clone());
+    // Source is (should be) a file, so pop the filename before setting the baseurl.
+    if !source.is_dir() {
+      source.pop();
     }
+    self.set_baseurl(&source);
   }
 
   /// Returns a function that resolves a binding to a configuration item.
diff --git a/crates/wick/wick-config/src/config/types_config.rs b/crates/wick/wick-config/src/config/types_config.rs
index 49ff0fb2c..3c21b9051 100644
--- a/crates/wick/wick-config/src/config/types_config.rs
+++ b/crates/wick/wick-config/src/config/types_config.rs
@@ -47,17 +47,12 @@ impl TypesConfiguration {
 
   /// Set the source location of the configuration.
   pub fn set_source(&mut self, source: &Path) {
-    // Source is a file, so our baseurl needs to be the parent directory.
-    // Remove the trailing filename from source.
-    if source.is_dir() {
-      self.set_baseurl(source);
-      self.source = Some(source.to_path_buf());
-    } else {
-      let mut s = source.to_path_buf();
-      s.pop();
-
-      self.set_baseurl(&s);
-      self.source = Some(s);
+    let mut source = source.to_path_buf();
+    self.source = Some(source.clone());
+    // Source is (should be) a file, so pop the filename before setting the baseurl.
+    if !source.is_dir() {
+      source.pop();
     }
+    self.set_baseurl(&source);
   }
 }


Test patch:
diff --git a/crates/wick/flow-graph-interpreter/tests/test/test_component.rs b/crates/wick/flow-graph-interpreter/tests/test/test_component.rs
index e24c12b74..e3d51de26 100644
--- a/crates/wick/flow-graph-interpreter/tests/test/test_component.rs
+++ b/crates/wick/flow-graph-interpreter/tests/test/test_component.rs
@@ -180,7 +180,7 @@ impl Component for TestComponent {
   }
 }
 
-fn handler(mut invocation: Invocation, callback: Arc<RuntimeCallback>) -> anyhow::Result<PacketStream> {
+fn handler(invocation: Invocation, callback: Arc<RuntimeCallback>) -> anyhow::Result<PacketStream> {
   let mut payload_stream = invocation.packets;
   let operation = invocation.target.operation_id();
   match operation {
diff --git a/crates/wick/wick-config/src/config/test_config.rs b/crates/wick/wick-config/src/config/test_config.rs
index e5768274b..885a90a80 100644
--- a/crates/wick/wick-config/src/config/test_config.rs
+++ b/crates/wick/wick-config/src/config/test_config.rs
@@ -19,17 +19,12 @@ pub struct TestConfiguration {
 impl TestConfiguration {
   /// Set the source location of the configuration.
   pub fn set_source(&mut self, source: &Path) {
-    // Source is a file, so our baseurl needs to be the parent directory.
-    // Remove the trailing filename from source.
-    if source.is_dir() {
-      self.set_baseurl(source);
-      self.source = Some(source.to_path_buf());
-    } else {
-      let mut s = source.to_path_buf();
-      s.pop();
-
-      self.set_baseurl(&s);
-      self.source = Some(s);
+    let mut source = source.to_path_buf();
+    self.source = Some(source.clone());
+    // Source is (should be) a file, so pop the filename before setting the baseurl.
+    if !source.is_dir() {
+      source.pop();
     }
+    self.set_baseurl(&source);
   }
 }