First step (#411)

This commit is contained in:
JT
2021-12-03 12:11:25 +13:00
committed by GitHub
parent d9bedaae2f
commit c5297d2b64
24 changed files with 178 additions and 151 deletions

View File

@ -220,29 +220,33 @@ impl EngineState {
// Updating the signatures plugin file with the added signatures
if let Some(plugin_path) = &self.plugin_signatures {
// Always creating the file which will erase previous signatures
let mut plugin_file = std::fs::File::create(plugin_path.as_path())
.map_err(|err| ShellError::InternalError(err.to_string()))?;
// Always create the file, which will erase previous signatures
if let Ok(mut plugin_file) = std::fs::File::create(plugin_path.as_path()) {
// Plugin definitions with parsed signature
for decl in self.plugin_decls() {
// A successful plugin registration already includes the plugin filename
// No need to check the None option
let path = decl.is_plugin().expect("plugin should have file name");
let file_name = path.to_str().expect("path should be a str");
// Plugin definitions with parsed signature
for decl in self.plugin_decls() {
// A successful plugin registration already includes the plugin filename
// No need to check the None option
let path = decl.is_plugin().expect("plugin should have file name");
let file_name = path.to_str().expect("path should be a str");
let line = serde_json::to_string_pretty(&decl.signature())
.map(|signature| format!("register {} {}\n", file_name, signature))
.map_err(|err| ShellError::PluginFailedToLoad(err.to_string()))?;
let line = serde_json::to_string_pretty(&decl.signature())
.map(|signature| format!("register {} {}\n", file_name, signature))
.map_err(|err| ShellError::InternalError(err.to_string()))?;
plugin_file
.write_all(line.as_bytes())
.map_err(|err| ShellError::InternalError(err.to_string()))?;
plugin_file
.write_all(line.as_bytes())
.map_err(|err| ShellError::PluginFailedToLoad(err.to_string()))?;
}
Ok(())
} else {
Err(ShellError::PluginFailedToLoad(
"Plugin file not found".into(),
))
}
Ok(())
} else {
Err(ShellError::InternalError("Plugin file not found".into()))
Err(ShellError::PluginFailedToLoad(
"Plugin file not found".into(),
))
}
}

View File

@ -46,7 +46,7 @@ impl Stack {
return Ok(v.clone());
}
Err(ShellError::InternalError("variable not found".into()))
Err(ShellError::NushellFailed("variable not found".into()))
}
pub fn add_var(&mut self, var_id: VarId, value: Value) {