mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 02:55:07 +02:00
First step (#411)
This commit is contained in:
@ -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(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -28,13 +28,15 @@ pub enum ShellError {
|
||||
|
||||
#[error("Pipeline mismatch.")]
|
||||
#[diagnostic(code(nu::shell::pipeline_mismatch), url(docsrs))]
|
||||
PipelineMismatch {
|
||||
expected: Type,
|
||||
#[label("expected: {expected}")]
|
||||
expected_span: Span,
|
||||
#[label("value originates from here")]
|
||||
origin: Span,
|
||||
},
|
||||
PipelineMismatch(
|
||||
String,
|
||||
#[label("expected: {0}")] Span,
|
||||
#[label("value originates from here")] Span,
|
||||
),
|
||||
|
||||
#[error("Type mismatch")]
|
||||
#[diagnostic(code(nu::shell::type_mismatch), url(docsrs))]
|
||||
TypeMismatch(String, #[label = "{0}"] Span),
|
||||
|
||||
#[error("Unsupported operator: {0}.")]
|
||||
#[diagnostic(code(nu::shell::unsupported_operator), url(docsrs))]
|
||||
@ -84,9 +86,10 @@ pub enum ShellError {
|
||||
#[diagnostic(code(nu::shell::invalid_range), url(docsrs))]
|
||||
InvalidRange(String, String, #[label = "expected a valid range"] Span),
|
||||
|
||||
#[error("Internal error: {0}.")]
|
||||
#[diagnostic(code(nu::shell::internal_error), url(docsrs))]
|
||||
InternalError(String),
|
||||
// Only use this one if we Nushell completely falls over and hits a state that isn't possible or isn't recoverable
|
||||
#[error("Nushell failed: {0}.")]
|
||||
#[diagnostic(code(nu::shell::nushell_failed), url(docsrs))]
|
||||
NushellFailed(String),
|
||||
|
||||
#[error("Variable not found!!!")]
|
||||
#[diagnostic(code(nu::shell::variable_not_found), url(docsrs))]
|
||||
@ -166,6 +169,14 @@ pub enum ShellError {
|
||||
#[diagnostic(code(nu::shell::file_not_found), url(docsrs))]
|
||||
FileNotFoundCustom(String, #[label("{0}")] Span),
|
||||
|
||||
#[error("Plugin failed to load")]
|
||||
#[diagnostic(code(nu::shell::plugin_fialed_to_load), url(docsrs))]
|
||||
PluginFailedToLoad(String),
|
||||
|
||||
#[error("I/O error")]
|
||||
#[diagnostic(code(nu::shell::io_error), url(docsrs))]
|
||||
IOError(String),
|
||||
|
||||
#[error("Directory not found")]
|
||||
#[diagnostic(code(nu::shell::directory_not_found), url(docsrs))]
|
||||
DirectoryNotFound(#[label("directory not found")] Span),
|
||||
@ -223,19 +234,19 @@ pub enum ShellError {
|
||||
|
||||
impl From<std::io::Error> for ShellError {
|
||||
fn from(input: std::io::Error) -> ShellError {
|
||||
ShellError::InternalError(format!("{:?}", input))
|
||||
ShellError::IOError(format!("{:?}", input))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Box<dyn std::error::Error>> for ShellError {
|
||||
fn from(input: Box<dyn std::error::Error>) -> ShellError {
|
||||
ShellError::InternalError(input.to_string())
|
||||
ShellError::IOError(input.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<dyn std::error::Error + Send + Sync>> for ShellError {
|
||||
fn from(input: Box<dyn std::error::Error + Send + Sync>) -> ShellError {
|
||||
ShellError::InternalError(format!("{:?}", input))
|
||||
ShellError::IOError(format!("{:?}", input))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user