summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-04-03 19:55:32 +0200
committertroido <troido@protonmail.com>2020-04-03 19:55:32 +0200
commit4e4f8d2462262ec8326e9f3e5a25ed580d098159 (patch)
tree99fe051e5509a7dbb5bd6ebd5feec005d3fbf41f
parentfd0bd24fa4e98b3bcd95a14ff844411727fb4433 (diff)
aerr! has formatting functionality; better errors; radishses -> radishes
-rw-r--r--content/encyclopediae/default_encyclopedia.json4
-rw-r--r--src/assemblage.rs6
-rw-r--r--src/componentparameter.rs4
-rw-r--r--src/componentwrapper.rs4
-rw-r--r--src/encyclopedia.rs2
-rw-r--r--src/main.rs2
-rw-r--r--src/persistence.rs6
-rw-r--r--src/server/address.rs2
-rw-r--r--src/util.rs2
9 files changed, 15 insertions, 17 deletions
diff --git a/content/encyclopediae/default_encyclopedia.json b/content/encyclopediae/default_encyclopedia.json
index e8a8379..0dc1f80 100644
--- a/content/encyclopediae/default_encyclopedia.json
+++ b/content/encyclopediae/default_encyclopedia.json
@@ -187,8 +187,8 @@
["Loot", {"loot": ["list", [
["list", [{"type": "radishseed"}, 0.92]],
["list", [{"type": "radishseed"}, 0.20]],
- ["list", [{"type": "radishses"}, 0.8]],
- ["list", [{"type": "radishses"}, 0.4]]
+ ["list", [{"type": "radishes"}, 0.8]],
+ ["list", [{"type": "radishes"}, 0.4]]
]]}]
],
"flags": ["Occupied"]
diff --git a/src/assemblage.rs b/src/assemblage.rs
index 0550617..52fd9f2 100644
--- a/src/assemblage.rs
+++ b/src/assemblage.rs
@@ -186,14 +186,14 @@ impl Assemblage {
None
}
};
- let param = value.ok_or(aerr!(&format!("argument <{:?}> has no value", (idx, (name, typ, def)))))?;
+ let param = value.ok_or(aerr!("argument <{:?}> has no value", (idx, (name, typ, def))))?;
if param.paramtype() != *typ {
- return Err(aerr!(&format!(
+ return Err(aerr!(
"argument has incorrect type: {:?}, {:?}, {:?}",
(idx, (name, typ, def)),
param.paramtype(),
param
- )));
+ ));
}
arguments.insert(name, param);
}
diff --git a/src/componentparameter.rs b/src/componentparameter.rs
index fb5ee87..28e77ce 100644
--- a/src/componentparameter.rs
+++ b/src/componentparameter.rs
@@ -65,7 +65,7 @@ impl ComponentParameter {
let typename = value.get(0).ok_or(aerr!("index 0 not in component parameter"))?.as_str().ok_or(aerr!("compparam type not a string"))?;
if let Some(paramtype) = ParameterType::from_str(typename) {
Ok(Self::Constant(Parameter::from_typed_json(paramtype, paramvalue).ok_or_else(||
- aerr!(& format!("failed to parse parameter constant: {:?} {:?}", paramtype, paramvalue))
+ aerr!("failed to parse parameter constant: {:?} {:?}", paramtype, paramvalue)
)?))
} else {
match typename {
@@ -91,7 +91,7 @@ impl ComponentParameter {
},
"self" => Ok(Self::TemplateSelf),
"name" => Ok(Self::TemplateName),
- _ => Err(aerr!(&format!("unknown compparam type '{}'", typename)))
+ _ => Err(aerr!("unknown compparam type '{}'", typename))
}
}
}
diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs
index 038b526..88a29f3 100644
--- a/src/componentwrapper.rs
+++ b/src/componentwrapper.rs
@@ -45,9 +45,9 @@ macro_rules! components {
use crate::components::$comp;
$(
let $paramname = match parameters.remove(stringify!($paramname))
- .ok_or(aerr!(&format!("required parameter '{}'not found", stringify!($paramname))))? {
+ .ok_or(aerr!("required parameter '{}'not found", stringify!($paramname)))? {
Parameter::$paramtype(p) => p,
- x => Err(aerr!(&format!("parameter type mismatch for parameter {}: {} {:?}", stringify!($paramname), stringify!($paramtype), x)))?
+ x => Err(aerr!("parameter type mismatch for parameter {}: {} {:?}", stringify!($paramname), stringify!($paramtype), x))?
};
)*
$creation
diff --git a/src/encyclopedia.rs b/src/encyclopedia.rs
index 75302b8..4e09f22 100644
--- a/src/encyclopedia.rs
+++ b/src/encyclopedia.rs
@@ -26,7 +26,7 @@ impl Encyclopedia {
}
pub fn construct(&self, template: &Template) -> Result<PreEntity> {
- let assemblage = self.items.get(&template.name).ok_or(aerr!("unknown assemblage name"))?;
+ let assemblage = self.items.get(&template.name).ok_or(aerr!("unknown assemblage name: '{:?}' in {:?}", template.name, template))?;
assemblage.instantiate(template)
}
diff --git a/src/main.rs b/src/main.rs
index b55c6a4..86999f6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -82,7 +82,7 @@ fn main() -> Result<()>{
let loader = WorldLoader::new(content_dir.join("maps"));
let save_dir = config.save_dir.unwrap_or(
- FileStorage::savedir().expect("couldn't find any save directory")
+ FileStorage::default_save_dir().expect("couldn't find any save directory")
);
println!("save directory: {:?}", content_dir);
let storage = FileStorage::new(save_dir);
diff --git a/src/persistence.rs b/src/persistence.rs
index bbf9595..9eb6e54 100644
--- a/src/persistence.rs
+++ b/src/persistence.rs
@@ -37,10 +37,8 @@ impl FileStorage {
}
}
- pub fn savedir() -> Option<PathBuf> {
- if let Some(pathname) = env::var_os("ASCIIFARM_SAVE_DIR") {
- Some(PathBuf::from(pathname))
- } else if let Some(pathname) = env::var_os("XDG_DATA_HOME") {
+ pub fn default_save_dir() -> Option<PathBuf> {
+ if let Some(pathname) = env::var_os("XDG_DATA_HOME") {
let mut path = PathBuf::from(pathname);
path.push("asciifarm");
path.push("saves");
diff --git a/src/server/address.rs b/src/server/address.rs
index 9fb7bea..1cf49ac 100644
--- a/src/server/address.rs
+++ b/src/server/address.rs
@@ -39,7 +39,7 @@ impl FromStr for Address {
"inet" => Ok(Address::Inet(text.parse()?)),
"unix" => Ok(Address::Unix(PathBuf::new().join(text))),
"abstract" => Ok(Address::Unix(PathBuf::new().join(&format!("\0{}", text)))),
- _ => Err(aerr!(&format!("'{}' is not a valid address type", typename)))
+ _ => Err(aerr!("'{}' is not a valid address type", typename))
}
}
}
diff --git a/src/util.rs b/src/util.rs
index 9b46d42..a5aca1a 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -38,7 +38,7 @@ impl Display for AError {
#[macro_export]
macro_rules! aerr {
- ($description:expr) => {Box::new(crate::util::AError::new($description))}
+ ($($description:tt)*) => {Box::new(crate::util::AError::new(&format!($($description)*)))}
}