nushell/crates/nu-protocol/src/parse_error.rs

617 lines
24 KiB
Rust
Raw Normal View History

use std::{
fmt::Display,
str::{from_utf8, Utf8Error},
};
use crate::{did_you_mean, Span, Type};
use miette::Diagnostic;
use serde::{Deserialize, Serialize};
use thiserror::Error;
2021-08-10 18:51:08 +00:00
#[derive(Clone, Debug, Error, Diagnostic, Serialize, Deserialize)]
2021-08-16 23:00:00 +00:00
pub enum ParseError {
/// The parser encountered unexpected tokens, when the code should have
/// finished. You should remove these or finish adding what you intended
/// to add.
#[error("Extra tokens in code.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::extra_tokens), help("Try removing them."))]
ExtraTokens(#[label = "extra tokens"] Span),
#[error("Extra positional argument.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::extra_positional), help("Usage: {0}"))]
2022-01-03 23:14:33 +00:00
ExtraPositional(String, #[label = "extra positional argument"] Span),
#[error("Required positional parameter after optional parameter")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::required_after_optional))]
2022-03-07 20:08:56 +00:00
RequiredAfterOptional(
String,
#[label = "required parameter {0} after optional parameter"] Span,
),
#[error("Unexpected end of code.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::unexpected_eof))]
2021-09-22 05:29:53 +00:00
UnexpectedEof(String, #[label("expected closing {0}")] Span),
#[error("Unclosed delimiter.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::unclosed_delimiter))]
Unclosed(String, #[label("unclosed {0}")] Span),
#[error("Unbalanced delimiter.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::unbalanced_delimiter))]
Unbalanced(String, String, #[label("unbalanced {0} and {1}")] Span),
#[error("Parse mismatch during operation.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::parse_mismatch))]
Expected(&'static str, #[label("expected {0}")] Span),
#[error("Parse mismatch during operation.")]
#[diagnostic(code(nu::parser::parse_mismatch_with_full_string_msg))]
ExpectedWithStringMsg(String, #[label("expected {0}")] Span),
Input output checking (#9680) # Description This PR tights input/output type-checking a bit more. There are a lot of commands that don't have correct input/output types, so part of the effort is updating them. This PR now contains updates to commands that had wrong input/output signatures. It doesn't add examples for these new signatures, but that can be follow-up work. # User-Facing Changes BREAKING CHANGE BREAKING CHANGE This work enforces many more checks on pipeline type correctness than previous nushell versions. This strictness may uncover incompatibilities in existing scripts or shortcomings in the type information for internal commands. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-07-14 03:20:35 +00:00
#[error("Command does not support {0} input.")]
#[diagnostic(code(nu::parser::input_type_mismatch))]
InputMismatch(Type, #[label("command doesn't support {0} input")] Span),
#[error("Command output doesn't match {0}.")]
#[diagnostic(code(nu::parser::output_type_mismatch))]
OutputMismatch(Type, #[label("command doesn't output {0}")] Span),
#[error("Type mismatch during operation.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::type_mismatch))]
Mismatch(String, String, #[label("expected {0}, found {1}")] Span), // expected, found, span
Better errors when bash-like operators are used (#7241) # Description Adds improved errors for when a user uses a bashism that nu doesn't support. fixes #7237 Examples: ``` Error: nu::parser::shell_andand (link) × The '&&' operator is not supported in Nushell ╭─[entry #1:1:1] 1 │ ls && ls · ─┬ · ╰── instead of '&&', use ';' or 'and' ╰──── help: use ';' instead of the shell '&&', or 'and' instead of the boolean '&&' ``` ``` Error: nu::parser::shell_oror (link) × The '||' operator is not supported in Nushell ╭─[entry #8:1:1] 1 │ ls || ls · ─┬ · ╰── instead of '||', use 'try' or 'or' ╰──── help: use 'try' instead of the shell '||', or 'or' instead of the boolean '||' ``` ``` Error: nu::parser::shell_err (link) × The '2>' shell operation is 'err>' in Nushell. ╭─[entry #9:1:1] 1 │ foo 2> bar.txt · ─┬ · ╰── use 'err>' instead of '2>' in Nushell ╰──── ``` ``` Error: nu::parser::shell_outerr (link) × The '2>&1' shell operation is 'out+err>' in Nushell. ╭─[entry #10:1:1] 1 │ foo 2>&1 bar.txt · ──┬─ · ╰── use 'out+err>' instead of '2>&1' in Nushell ╰──── help: Nushell redirection will write all of stdout before stderr. ``` # User-Facing Changes **BREAKING CHANGES** This removes the `&&` and `||` operators. We previously supported by `&&`/`and` and `||`/`or`. With this change, only `and` and `or` are valid boolean operators. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2022-12-07 23:02:11 +00:00
#[error("The '&&' operator is not supported in Nushell")]
#[diagnostic(
code(nu::parser::shell_andand),
help("use ';' instead of the shell '&&', or 'and' instead of the boolean '&&'")
)]
ShellAndAnd(#[label("instead of '&&', use ';' or 'and'")] Span),
#[error("The '||' operator is not supported in Nushell")]
#[diagnostic(
code(nu::parser::shell_oror),
help("use 'try' instead of the shell '||', or 'or' instead of the boolean '||'")
)]
ShellOrOr(#[label("instead of '||', use 'try' or 'or'")] Span),
#[error("The '2>' shell operation is 'err>' in Nushell.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::shell_err))]
Better errors when bash-like operators are used (#7241) # Description Adds improved errors for when a user uses a bashism that nu doesn't support. fixes #7237 Examples: ``` Error: nu::parser::shell_andand (link) × The '&&' operator is not supported in Nushell ╭─[entry #1:1:1] 1 │ ls && ls · ─┬ · ╰── instead of '&&', use ';' or 'and' ╰──── help: use ';' instead of the shell '&&', or 'and' instead of the boolean '&&' ``` ``` Error: nu::parser::shell_oror (link) × The '||' operator is not supported in Nushell ╭─[entry #8:1:1] 1 │ ls || ls · ─┬ · ╰── instead of '||', use 'try' or 'or' ╰──── help: use 'try' instead of the shell '||', or 'or' instead of the boolean '||' ``` ``` Error: nu::parser::shell_err (link) × The '2>' shell operation is 'err>' in Nushell. ╭─[entry #9:1:1] 1 │ foo 2> bar.txt · ─┬ · ╰── use 'err>' instead of '2>' in Nushell ╰──── ``` ``` Error: nu::parser::shell_outerr (link) × The '2>&1' shell operation is 'out+err>' in Nushell. ╭─[entry #10:1:1] 1 │ foo 2>&1 bar.txt · ──┬─ · ╰── use 'out+err>' instead of '2>&1' in Nushell ╰──── help: Nushell redirection will write all of stdout before stderr. ``` # User-Facing Changes **BREAKING CHANGES** This removes the `&&` and `||` operators. We previously supported by `&&`/`and` and `||`/`or`. With this change, only `and` and `or` are valid boolean operators. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2022-12-07 23:02:11 +00:00
ShellErrRedirect(#[label("use 'err>' instead of '2>' in Nushell")] Span),
#[error("The '2>&1' shell operation is 'out+err>' in Nushell.")]
#[diagnostic(
code(nu::parser::shell_outerr),
help("Nushell redirection will write all of stdout before stderr.")
)]
ShellOutErrRedirect(#[label("use 'out+err>' instead of '2>&1' in Nushell")] Span),
improve operation mismatch errors (#8800) # Description This improves the operation mismatch error in a few ways: * We now detect if the left-hand side of the operation is at fault, and show a simpler error/error message if it is * Removed the unhelpful hint * Updated the error text to make it clear what types are causing the issue ![image](https://user-images.githubusercontent.com/547158/230666329-537a8cae-6350-4ee7-878e-777e05c4f265.png) ![image](https://user-images.githubusercontent.com/547158/230666353-93529dc2-039a-4774-a84c-a6faac94d8e2.png) # User-Facing Changes Error texts and spans will change # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-utils/standard_library/tests.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-04-07 21:32:44 +00:00
#[error("{0} is not supported on values of type {3}")]
#[diagnostic(code(nu::parser::unsupported_operation))]
UnsupportedOperationLHS(
String,
#[label = "doesn't support this value"] Span,
#[label("{3}")] Span,
Type,
),
#[error("{0} is not supported between {3} and {5}.")]
#[diagnostic(code(nu::parser::unsupported_operation))]
UnsupportedOperationRHS(
String,
#[label = "doesn't support these values"] Span,
#[label("{3}")] Span,
Type,
improve operation mismatch errors (#8800) # Description This improves the operation mismatch error in a few ways: * We now detect if the left-hand side of the operation is at fault, and show a simpler error/error message if it is * Removed the unhelpful hint * Updated the error text to make it clear what types are causing the issue ![image](https://user-images.githubusercontent.com/547158/230666329-537a8cae-6350-4ee7-878e-777e05c4f265.png) ![image](https://user-images.githubusercontent.com/547158/230666353-93529dc2-039a-4774-a84c-a6faac94d8e2.png) # User-Facing Changes Error texts and spans will change # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-utils/standard_library/tests.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-04-07 21:32:44 +00:00
#[label("{5}")] Span,
Type,
),
#[error("Capture of mutable variable.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::expected_keyword))]
CaptureOfMutableVar(#[label("capture of mutable variable")] Span),
#[error("Expected keyword.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::expected_keyword))]
ExpectedKeyword(String, #[label("expected {0}")] Span),
#[error("Unexpected keyword.")]
#[diagnostic(
code(nu::parser::unexpected_keyword),
help("'{0}' keyword is allowed only in a module.")
)]
UnexpectedKeyword(String, #[label("unexpected {0}")] Span),
2023-03-10 21:20:31 +00:00
#[error("Can't create alias to parser keyword.")]
#[diagnostic(
code(nu::parser::cant_alias_keyword),
help("Only the following keywords can be aliased: {0}.")
)]
CantAliasKeyword(String, #[label("not supported in alias")] Span),
#[error("Can't create alias to expression.")]
#[diagnostic(
code(nu::parser::cant_alias_expression),
help("Only command calls can be aliased.")
)]
CantAliasExpression(String, #[label("aliasing {0} is not supported")] Span),
#[error("Unknown operator")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::unknown_operator), help("{1}"))]
UnknownOperator(
&'static str,
&'static str,
#[label("Operator '{0}' not supported")] Span,
),
#[error("Statement used in pipeline.")]
#[diagnostic(
code(nu::parser::unexpected_keyword),
help(
"'{0}' keyword is not allowed in pipeline. Use '{0}' by itself, outside of a pipeline."
)
)]
BuiltinCommandInPipeline(String, #[label("not allowed in pipeline")] Span),
#[error("{0} statement used in pipeline.")]
#[diagnostic(
code(nu::parser::unexpected_keyword),
help(
"Assigning '{1}' to '{2}' does not produce a value to be piped. If the pipeline result is meant to be assigned to '{2}', use '{0} {2} = ({1} | ...)'."
)
)]
AssignInPipeline(String, String, String, #[label("'{0}' in pipeline")] Span),
#[error("`{0}` used as variable name.")]
#[diagnostic(
code(nu::parser::name_is_builtin_var),
help(
"'{0}' is the name of a builtin Nushell variable and cannot be used as a variable name"
)
)]
NameIsBuiltinVar(String, #[label("already a builtin variable")] Span),
#[error("Incorrect value")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::incorrect_value), help("{2}"))]
IncorrectValue(String, #[label("unexpected {0}")] Span, String),
#[error("Multiple rest params.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::multiple_rest_params))]
MultipleRestParams(#[label = "multiple rest params"] Span),
#[error("Variable not found.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::variable_not_found))]
VariableNotFound(DidYouMean, #[label = "variable not found. {0}"] Span),
Better error message if env var is used as var (#9522) # Description This PR improves the error message if an environment variable (that's visible before the parser begins) is used in the form of `$PATH` instead of `$env.PATH`. Before: ``` Error: nu::parser::variable_not_found × Variable not found. ╭─[entry #31:1:1] 1 │ echo $PATH · ──┬── · ╰── variable not found. ╰──── ``` After: ``` Error: nu::parser::env_var_not_var × Use $env.PATH instead of $PATH. ╭─[entry #1:1:1] 1 │ echo $PATH · ──┬── · ╰── use $env.PATH instead of $PATH ╰──── ``` # User-Facing Changes Just the improvement to the error message # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-06-25 17:59:56 +00:00
#[error("Use $env.{0} instead of ${0}.")]
#[diagnostic(code(nu::parser::env_var_not_var))]
EnvVarNotVar(String, #[label = "use $env.{0} instead of ${0}"] Span),
2021-10-12 05:08:55 +00:00
#[error("Variable name not supported.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::variable_not_valid))]
2021-10-12 05:08:55 +00:00
VariableNotValid(#[label = "variable name can't contain spaces or quotes"] Span),
#[error("Alias name not supported.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::variable_not_valid))]
AliasNotValid(
#[label = "alias name can't be a number, a filesize, or contain a hash # or caret ^"] Span,
),
#[error("Command name not supported.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::variable_not_valid))]
CommandDefNotValid(
#[label = "command name can't be a number, a filesize, or contain a hash # or caret ^"]
Span,
),
2021-09-26 10:25:52 +00:00
#[error("Module not found.")]
#[diagnostic(
code(nu::parser::module_not_found),
help("module files and their paths must be available before your script is run as parsing occurs before anything is evaluated")
)]
2021-09-26 10:25:52 +00:00
ModuleNotFound(#[label = "module not found"] Span),
#[error("Missing mod.nu file.")]
#[diagnostic(
code(nu::parser::module_missing_mod_nu_file),
help("Directory {0} is missing a mod.nu file.\n\nWhen importing a directory as a Nushell module, it needs to contain a mod.nu file (can be empty). Alternatively, you can use .nu files in the directory as modules individually.")
)]
ModuleMissingModNuFile(
String,
#[label = "module directory is missing a mod.nu file"] Span,
),
#[error("Cyclical module import.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::cyclical_module_import), help("{0}"))]
CyclicalModuleImport(String, #[label = "detected cyclical module import"] Span),
#[error("Can't export {0} named same as the module.")]
#[diagnostic(
code(nu::parser::named_as_module),
help("Module {1} can't export {0} named the same as the module. Either change the module name, or export `{2}` {0}.")
)]
NamedAsModule(
String,
String,
String,
#[label = "can't export from module {1}"] Span,
),
#[error("Module already contains 'main' command.")]
#[diagnostic(
code(nu::parser::module_double_main),
help("Tried to add 'main' command to module '{0}' but it has already been added.")
)]
ModuleDoubleMain(
String,
#[label = "module '{0}' already contains 'main'"] Span,
),
#[error("Invalid module file name")]
#[diagnostic(
code(nu::parser::invalid_module_file_name),
help("File {0} resolves to module name {1} which is the same as the parent module. Either rename the file or, save it as 'mod.nu' to define the parent module.")
)]
InvalidModuleFileName(
String,
String,
#[label = "submodule can't have the same name as the parent module"] Span,
),
#[error("Can't export alias defined as 'main'.")]
#[diagnostic(
code(nu::parser::export_main_alias_not_allowed),
help("Exporting aliases as 'main' is not allowed. Either rename the alias or convert it to a custom command.")
)]
ExportMainAliasNotAllowed(#[label = "can't export from module"] Span),
Overlays (#5375) * WIP: Start laying overlays * Rename Overlay->Module; Start adding overlay * Revamp adding overlay * Add overlay add tests; Disable debug print * Fix overlay add; Add overlay remove * Add overlay remove tests * Add missing overlay remove file * Add overlay list command * (WIP?) Enable overlays for env vars * Move OverlayFrames to ScopeFrames * (WIP) Move everything to overlays only ScopeFrame contains nothing but overlays now * Fix predecls * Fix wrong overlay id translation and aliases * Fix broken env lookup logic * Remove TODOs * Add overlay add + remove for environment * Add a few overlay tests; Fix overlay add name * Some cleanup; Fix overlay add/remove names * Clippy * Fmt * Remove walls of comments * List overlays from stack; Add debugging flag Currently, the engine state ordering is somehow broken. * Fix (?) overlay list test * Fix tests on Windows * Fix activated overlay ordering * Check for active overlays equality in overlay list This removes the -p flag: Either both parser and engine will have the same overlays, or the command will fail. * Add merging on overlay remove * Change help message and comment * Add some remove-merge/discard tests * (WIP) Track removed overlays properly * Clippy; Fmt * Fix getting last overlay; Fix predecls in overlays * Remove merging; Fix re-add overwriting stuff Also some error message tweaks. * Fix overlay error in the engine * Update variable_completions.rs * Adds flags and optional arguments to view-source (#5446) * added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt * fix bug in shell_integration (#5450) * fix bug in shell_integration * add some comments * enable cd to work with directory abbreviations (#5452) * enable cd to work with abbreviations * add abbreviation example * fix tests * make it configurable * make cd recornize symblic link (#5454) * implement seq char command to generate single character sequence (#5453) * add tmp code * add seq char command * Add split number flag in `split row` (#5434) Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com> * Add two more overlay tests * Add ModuleId to OverlayFrame * Fix env conversion accidentally activating overlay It activated overlay from permanent state prematurely which would cause `overlay add` to misbehave. * Remove unused parameter; Add overlay list test * Remove added traces * Add overlay commands examples * Modify TODO * Fix $nu.scope iteration * Disallow removing default overlay * Refactor some parser errors * Remove last overlay if no argument * Diversify overlay examples * Make it possible to update overlay's module In case the origin module updates, the overlay add loads the new module, makes it overlay's origin and applies the changes. Before, it was impossible to update the overlay if the module changed. Co-authored-by: JT <547158+jntrnr@users.noreply.github.com> Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <WindSoilder@outlook.com> Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-07 19:39:22 +00:00
#[error("Active overlay not found.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::active_overlay_not_found))]
Overlays (#5375) * WIP: Start laying overlays * Rename Overlay->Module; Start adding overlay * Revamp adding overlay * Add overlay add tests; Disable debug print * Fix overlay add; Add overlay remove * Add overlay remove tests * Add missing overlay remove file * Add overlay list command * (WIP?) Enable overlays for env vars * Move OverlayFrames to ScopeFrames * (WIP) Move everything to overlays only ScopeFrame contains nothing but overlays now * Fix predecls * Fix wrong overlay id translation and aliases * Fix broken env lookup logic * Remove TODOs * Add overlay add + remove for environment * Add a few overlay tests; Fix overlay add name * Some cleanup; Fix overlay add/remove names * Clippy * Fmt * Remove walls of comments * List overlays from stack; Add debugging flag Currently, the engine state ordering is somehow broken. * Fix (?) overlay list test * Fix tests on Windows * Fix activated overlay ordering * Check for active overlays equality in overlay list This removes the -p flag: Either both parser and engine will have the same overlays, or the command will fail. * Add merging on overlay remove * Change help message and comment * Add some remove-merge/discard tests * (WIP) Track removed overlays properly * Clippy; Fmt * Fix getting last overlay; Fix predecls in overlays * Remove merging; Fix re-add overwriting stuff Also some error message tweaks. * Fix overlay error in the engine * Update variable_completions.rs * Adds flags and optional arguments to view-source (#5446) * added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt * fix bug in shell_integration (#5450) * fix bug in shell_integration * add some comments * enable cd to work with directory abbreviations (#5452) * enable cd to work with abbreviations * add abbreviation example * fix tests * make it configurable * make cd recornize symblic link (#5454) * implement seq char command to generate single character sequence (#5453) * add tmp code * add seq char command * Add split number flag in `split row` (#5434) Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com> * Add two more overlay tests * Add ModuleId to OverlayFrame * Fix env conversion accidentally activating overlay It activated overlay from permanent state prematurely which would cause `overlay add` to misbehave. * Remove unused parameter; Add overlay list test * Remove added traces * Add overlay commands examples * Modify TODO * Fix $nu.scope iteration * Disallow removing default overlay * Refactor some parser errors * Remove last overlay if no argument * Diversify overlay examples * Make it possible to update overlay's module In case the origin module updates, the overlay add loads the new module, makes it overlay's origin and applies the changes. Before, it was impossible to update the overlay if the module changed. Co-authored-by: JT <547158+jntrnr@users.noreply.github.com> Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <WindSoilder@outlook.com> Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-07 19:39:22 +00:00
ActiveOverlayNotFound(#[label = "not an active overlay"] Span),
#[error("Overlay prefix mismatch.")]
#[diagnostic(
code(nu::parser::overlay_prefix_mismatch),
help("Overlay {0} already exists {1} a prefix. To add it again, do it {1} the --prefix flag.")
)]
OverlayPrefixMismatch(
String,
String,
#[label = "already exists {1} a prefix"] Span,
),
Overlays (#5375) * WIP: Start laying overlays * Rename Overlay->Module; Start adding overlay * Revamp adding overlay * Add overlay add tests; Disable debug print * Fix overlay add; Add overlay remove * Add overlay remove tests * Add missing overlay remove file * Add overlay list command * (WIP?) Enable overlays for env vars * Move OverlayFrames to ScopeFrames * (WIP) Move everything to overlays only ScopeFrame contains nothing but overlays now * Fix predecls * Fix wrong overlay id translation and aliases * Fix broken env lookup logic * Remove TODOs * Add overlay add + remove for environment * Add a few overlay tests; Fix overlay add name * Some cleanup; Fix overlay add/remove names * Clippy * Fmt * Remove walls of comments * List overlays from stack; Add debugging flag Currently, the engine state ordering is somehow broken. * Fix (?) overlay list test * Fix tests on Windows * Fix activated overlay ordering * Check for active overlays equality in overlay list This removes the -p flag: Either both parser and engine will have the same overlays, or the command will fail. * Add merging on overlay remove * Change help message and comment * Add some remove-merge/discard tests * (WIP) Track removed overlays properly * Clippy; Fmt * Fix getting last overlay; Fix predecls in overlays * Remove merging; Fix re-add overwriting stuff Also some error message tweaks. * Fix overlay error in the engine * Update variable_completions.rs * Adds flags and optional arguments to view-source (#5446) * added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt * fix bug in shell_integration (#5450) * fix bug in shell_integration * add some comments * enable cd to work with directory abbreviations (#5452) * enable cd to work with abbreviations * add abbreviation example * fix tests * make it configurable * make cd recornize symblic link (#5454) * implement seq char command to generate single character sequence (#5453) * add tmp code * add seq char command * Add split number flag in `split row` (#5434) Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com> * Add two more overlay tests * Add ModuleId to OverlayFrame * Fix env conversion accidentally activating overlay It activated overlay from permanent state prematurely which would cause `overlay add` to misbehave. * Remove unused parameter; Add overlay list test * Remove added traces * Add overlay commands examples * Modify TODO * Fix $nu.scope iteration * Disallow removing default overlay * Refactor some parser errors * Remove last overlay if no argument * Diversify overlay examples * Make it possible to update overlay's module In case the origin module updates, the overlay add loads the new module, makes it overlay's origin and applies the changes. Before, it was impossible to update the overlay if the module changed. Co-authored-by: JT <547158+jntrnr@users.noreply.github.com> Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <WindSoilder@outlook.com> Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-07 19:39:22 +00:00
#[error("Module or overlay not found.")]
#[diagnostic(
code(nu::parser::module_or_overlay_not_found),
help("Requires either an existing overlay, a module, or an import pattern defining a module.")
)]
ModuleOrOverlayNotFound(#[label = "not a module or an overlay"] Span),
#[error("Cannot remove the last overlay.")]
#[diagnostic(
code(nu::parser::cant_remove_last_overlay),
help("At least one overlay must always be active.")
)]
CantRemoveLastOverlay(#[label = "this is the last overlay, can't remove it"] Span),
#[error("Cannot hide default overlay.")]
Overlays (#5375) * WIP: Start laying overlays * Rename Overlay->Module; Start adding overlay * Revamp adding overlay * Add overlay add tests; Disable debug print * Fix overlay add; Add overlay remove * Add overlay remove tests * Add missing overlay remove file * Add overlay list command * (WIP?) Enable overlays for env vars * Move OverlayFrames to ScopeFrames * (WIP) Move everything to overlays only ScopeFrame contains nothing but overlays now * Fix predecls * Fix wrong overlay id translation and aliases * Fix broken env lookup logic * Remove TODOs * Add overlay add + remove for environment * Add a few overlay tests; Fix overlay add name * Some cleanup; Fix overlay add/remove names * Clippy * Fmt * Remove walls of comments * List overlays from stack; Add debugging flag Currently, the engine state ordering is somehow broken. * Fix (?) overlay list test * Fix tests on Windows * Fix activated overlay ordering * Check for active overlays equality in overlay list This removes the -p flag: Either both parser and engine will have the same overlays, or the command will fail. * Add merging on overlay remove * Change help message and comment * Add some remove-merge/discard tests * (WIP) Track removed overlays properly * Clippy; Fmt * Fix getting last overlay; Fix predecls in overlays * Remove merging; Fix re-add overwriting stuff Also some error message tweaks. * Fix overlay error in the engine * Update variable_completions.rs * Adds flags and optional arguments to view-source (#5446) * added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt * fix bug in shell_integration (#5450) * fix bug in shell_integration * add some comments * enable cd to work with directory abbreviations (#5452) * enable cd to work with abbreviations * add abbreviation example * fix tests * make it configurable * make cd recornize symblic link (#5454) * implement seq char command to generate single character sequence (#5453) * add tmp code * add seq char command * Add split number flag in `split row` (#5434) Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com> * Add two more overlay tests * Add ModuleId to OverlayFrame * Fix env conversion accidentally activating overlay It activated overlay from permanent state prematurely which would cause `overlay add` to misbehave. * Remove unused parameter; Add overlay list test * Remove added traces * Add overlay commands examples * Modify TODO * Fix $nu.scope iteration * Disallow removing default overlay * Refactor some parser errors * Remove last overlay if no argument * Diversify overlay examples * Make it possible to update overlay's module In case the origin module updates, the overlay add loads the new module, makes it overlay's origin and applies the changes. Before, it was impossible to update the overlay if the module changed. Co-authored-by: JT <547158+jntrnr@users.noreply.github.com> Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <WindSoilder@outlook.com> Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-07 19:39:22 +00:00
#[diagnostic(
code(nu::parser::cant_hide_default_overlay),
help("'{0}' is a default overlay. Default overlays cannot be hidden.")
Overlays (#5375) * WIP: Start laying overlays * Rename Overlay->Module; Start adding overlay * Revamp adding overlay * Add overlay add tests; Disable debug print * Fix overlay add; Add overlay remove * Add overlay remove tests * Add missing overlay remove file * Add overlay list command * (WIP?) Enable overlays for env vars * Move OverlayFrames to ScopeFrames * (WIP) Move everything to overlays only ScopeFrame contains nothing but overlays now * Fix predecls * Fix wrong overlay id translation and aliases * Fix broken env lookup logic * Remove TODOs * Add overlay add + remove for environment * Add a few overlay tests; Fix overlay add name * Some cleanup; Fix overlay add/remove names * Clippy * Fmt * Remove walls of comments * List overlays from stack; Add debugging flag Currently, the engine state ordering is somehow broken. * Fix (?) overlay list test * Fix tests on Windows * Fix activated overlay ordering * Check for active overlays equality in overlay list This removes the -p flag: Either both parser and engine will have the same overlays, or the command will fail. * Add merging on overlay remove * Change help message and comment * Add some remove-merge/discard tests * (WIP) Track removed overlays properly * Clippy; Fmt * Fix getting last overlay; Fix predecls in overlays * Remove merging; Fix re-add overwriting stuff Also some error message tweaks. * Fix overlay error in the engine * Update variable_completions.rs * Adds flags and optional arguments to view-source (#5446) * added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt * fix bug in shell_integration (#5450) * fix bug in shell_integration * add some comments * enable cd to work with directory abbreviations (#5452) * enable cd to work with abbreviations * add abbreviation example * fix tests * make it configurable * make cd recornize symblic link (#5454) * implement seq char command to generate single character sequence (#5453) * add tmp code * add seq char command * Add split number flag in `split row` (#5434) Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com> * Add two more overlay tests * Add ModuleId to OverlayFrame * Fix env conversion accidentally activating overlay It activated overlay from permanent state prematurely which would cause `overlay add` to misbehave. * Remove unused parameter; Add overlay list test * Remove added traces * Add overlay commands examples * Modify TODO * Fix $nu.scope iteration * Disallow removing default overlay * Refactor some parser errors * Remove last overlay if no argument * Diversify overlay examples * Make it possible to update overlay's module In case the origin module updates, the overlay add loads the new module, makes it overlay's origin and applies the changes. Before, it was impossible to update the overlay if the module changed. Co-authored-by: JT <547158+jntrnr@users.noreply.github.com> Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <WindSoilder@outlook.com> Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-07 19:39:22 +00:00
)]
CantHideDefaultOverlay(String, #[label = "can't hide overlay"] Span),
Overlays (#5375) * WIP: Start laying overlays * Rename Overlay->Module; Start adding overlay * Revamp adding overlay * Add overlay add tests; Disable debug print * Fix overlay add; Add overlay remove * Add overlay remove tests * Add missing overlay remove file * Add overlay list command * (WIP?) Enable overlays for env vars * Move OverlayFrames to ScopeFrames * (WIP) Move everything to overlays only ScopeFrame contains nothing but overlays now * Fix predecls * Fix wrong overlay id translation and aliases * Fix broken env lookup logic * Remove TODOs * Add overlay add + remove for environment * Add a few overlay tests; Fix overlay add name * Some cleanup; Fix overlay add/remove names * Clippy * Fmt * Remove walls of comments * List overlays from stack; Add debugging flag Currently, the engine state ordering is somehow broken. * Fix (?) overlay list test * Fix tests on Windows * Fix activated overlay ordering * Check for active overlays equality in overlay list This removes the -p flag: Either both parser and engine will have the same overlays, or the command will fail. * Add merging on overlay remove * Change help message and comment * Add some remove-merge/discard tests * (WIP) Track removed overlays properly * Clippy; Fmt * Fix getting last overlay; Fix predecls in overlays * Remove merging; Fix re-add overwriting stuff Also some error message tweaks. * Fix overlay error in the engine * Update variable_completions.rs * Adds flags and optional arguments to view-source (#5446) * added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt * fix bug in shell_integration (#5450) * fix bug in shell_integration * add some comments * enable cd to work with directory abbreviations (#5452) * enable cd to work with abbreviations * add abbreviation example * fix tests * make it configurable * make cd recornize symblic link (#5454) * implement seq char command to generate single character sequence (#5453) * add tmp code * add seq char command * Add split number flag in `split row` (#5434) Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com> * Add two more overlay tests * Add ModuleId to OverlayFrame * Fix env conversion accidentally activating overlay It activated overlay from permanent state prematurely which would cause `overlay add` to misbehave. * Remove unused parameter; Add overlay list test * Remove added traces * Add overlay commands examples * Modify TODO * Fix $nu.scope iteration * Disallow removing default overlay * Refactor some parser errors * Remove last overlay if no argument * Diversify overlay examples * Make it possible to update overlay's module In case the origin module updates, the overlay add loads the new module, makes it overlay's origin and applies the changes. Before, it was impossible to update the overlay if the module changed. Co-authored-by: JT <547158+jntrnr@users.noreply.github.com> Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <WindSoilder@outlook.com> Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-07 19:39:22 +00:00
#[error("Cannot add overlay.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::cant_add_overlay_help), help("{0}"))]
CantAddOverlayHelp(String, #[label = "cannot add this overlay"] Span),
#[error("Not found.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::not_found))]
NotFound(#[label = "did not find anything under this name"] Span),
#[error("Duplicate command definition within a block.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::duplicate_command_def))]
DuplicateCommandDef(#[label = "defined more than once"] Span),
#[error("Unknown command.")]
#[diagnostic(
code(nu::parser::unknown_command),
2021-10-12 17:44:23 +00:00
// TODO: actual suggestions like "Did you mean `foo`?"
)]
UnknownCommand(#[label = "unknown command"] Span),
#[error("Non-UTF8 string.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::non_utf8))]
NonUtf8(#[label = "non-UTF8 string"] Span),
2021-09-21 04:03:06 +00:00
#[error("The `{0}` command doesn't have flag `{1}`.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::unknown_flag), help("{3}"))]
UnknownFlag(String, String, #[label = "unknown flag"] Span, String),
#[error("Unknown type.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::unknown_type))]
UnknownType(#[label = "unknown type"] Span),
2022-01-03 23:14:33 +00:00
#[error("Missing flag argument.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::missing_flag_param))]
2022-01-03 23:14:33 +00:00
MissingFlagParam(String, #[label = "flag missing {0} argument"] Span),
#[error("Only the last flag in a short flag batch can take an argument.")]
#[diagnostic(code(nu::parser::only_last_flag_in_batch_can_take_arg))]
OnlyLastFlagInBatchCanTakeArg(#[label = "only the last flag can take args"] Span),
#[error("Missing required positional argument.")]
better help message for MissingPositional error (#10949) Added "Use `--help` for more information." to the help of MissingPositional error - this PR should close [#10946](https://github.com/nushell/nushell/issues/10946) **Before:** ![image](https://github.com/nushell/nushell/assets/1835944/629aeaae-e985-41aa-a791-05ef062e988e) **After:** ![image](https://github.com/nushell/nushell/assets/1835944/0bc1868c-ffed-4440-ad98-2cf29aa8c656) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: Denis Zorya <denis.zorya@trafigura.com>
2023-11-04 17:24:21 +00:00
#[diagnostic(
code(nu::parser::missing_positional),
help("Usage: {2}. Use `--help` for more information.")
)]
2022-01-03 23:14:33 +00:00
MissingPositional(String, #[label("missing {0}")] Span, String),
2022-01-03 23:14:33 +00:00
#[error("Missing argument to `{1}`.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::keyword_missing_arg))]
2022-01-03 23:14:33 +00:00
KeywordMissingArgument(
String,
String,
#[label("missing {0} value that follows {1}")] Span,
),
#[error("Missing type.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::missing_type))]
MissingType(#[label = "expected type"] Span),
#[error("Type mismatch.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::type_mismatch))]
TypeMismatch(Type, Type, #[label("expected {0}, found {1}")] Span), // expected, found, span
#[error("Type mismatch.")]
#[diagnostic(code(nu::parser::type_mismatch_help), help("{3}"))]
TypeMismatchHelp(Type, Type, #[label("expected {0}, found {1}")] Span, String), // expected, found, span, help
#[error("Missing required flag.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::missing_required_flag))]
MissingRequiredFlag(String, #[label("missing required flag {0}")] Span),
#[error("Incomplete math expression.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::incomplete_math_expression))]
IncompleteMathExpression(#[label = "incomplete math expression"] Span),
#[error("Unknown state.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::unknown_state))]
UnknownState(String, #[label("{0}")] Span),
#[error("Internal error.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::unknown_state))]
InternalError(String, #[label("{0}")] Span),
#[error("Parser incomplete.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::parser_incomplete))]
IncompleteParser(#[label = "parser support missing for this expression"] Span),
#[error("Rest parameter needs a name.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::rest_needs_name))]
RestNeedsName(#[label = "needs a parameter name"] Span),
#[error("Parameter not correct type.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::parameter_mismatch_type))]
ParameterMismatchType(
String,
String,
String,
#[label = "parameter {0} needs to be '{1}' instead of '{2}'"] Span,
),
#[error("Default values should be constant expressions.")]
#[diagnostic(code(nu::parser::non_constant_default_value))]
NonConstantDefaultValue(#[label = "expected a constant value"] Span),
#[error("Extra columns.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::extra_columns))]
ExtraColumns(
usize,
#[label("expected {0} column{}", if *.0 == 1 { "" } else { "s" })] Span,
),
#[error("Missing columns.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::missing_columns))]
MissingColumns(
usize,
#[label("expected {0} column{}", if *.0 == 1 { "" } else { "s" })] Span,
),
#[error("{0}")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::assignment_mismatch))]
AssignmentMismatch(String, String, #[label("{1}")] Span),
2021-09-26 18:39:19 +00:00
#[error("Missing import pattern.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::missing_import_pattern))]
2021-09-26 18:39:19 +00:00
MissingImportPattern(#[label = "needs an import pattern"] Span),
#[error("Wrong import pattern structure.")]
#[diagnostic(code(nu::parser::wrong_import_pattern))]
WrongImportPattern(String, #[label = "{0}"] Span),
#[error("Export not found.")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::export_not_found))]
2021-09-26 18:39:19 +00:00
ExportNotFound(#[label = "could not find imports"] Span),
2021-10-31 08:17:01 +00:00
#[error("File not found")]
#[diagnostic(
code(nu::parser::sourced_file_not_found),
help("sourced files need to be available before your script is run")
)]
SourcedFileNotFound(String, #[label("File not found: {0}")] Span),
#[error("File not found")]
#[diagnostic(
code(nu::parser::registered_file_not_found),
help("registered files need to be available before your script is run")
)]
RegisteredFileNotFound(String, #[label("File not found: {0}")] Span),
#[error("File not found")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::parser::file_not_found))]
FileNotFound(String, #[label("File not found: {0}")] Span),
2021-10-31 08:17:01 +00:00
Overlays (#5375) * WIP: Start laying overlays * Rename Overlay->Module; Start adding overlay * Revamp adding overlay * Add overlay add tests; Disable debug print * Fix overlay add; Add overlay remove * Add overlay remove tests * Add missing overlay remove file * Add overlay list command * (WIP?) Enable overlays for env vars * Move OverlayFrames to ScopeFrames * (WIP) Move everything to overlays only ScopeFrame contains nothing but overlays now * Fix predecls * Fix wrong overlay id translation and aliases * Fix broken env lookup logic * Remove TODOs * Add overlay add + remove for environment * Add a few overlay tests; Fix overlay add name * Some cleanup; Fix overlay add/remove names * Clippy * Fmt * Remove walls of comments * List overlays from stack; Add debugging flag Currently, the engine state ordering is somehow broken. * Fix (?) overlay list test * Fix tests on Windows * Fix activated overlay ordering * Check for active overlays equality in overlay list This removes the -p flag: Either both parser and engine will have the same overlays, or the command will fail. * Add merging on overlay remove * Change help message and comment * Add some remove-merge/discard tests * (WIP) Track removed overlays properly * Clippy; Fmt * Fix getting last overlay; Fix predecls in overlays * Remove merging; Fix re-add overwriting stuff Also some error message tweaks. * Fix overlay error in the engine * Update variable_completions.rs * Adds flags and optional arguments to view-source (#5446) * added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt * fix bug in shell_integration (#5450) * fix bug in shell_integration * add some comments * enable cd to work with directory abbreviations (#5452) * enable cd to work with abbreviations * add abbreviation example * fix tests * make it configurable * make cd recornize symblic link (#5454) * implement seq char command to generate single character sequence (#5453) * add tmp code * add seq char command * Add split number flag in `split row` (#5434) Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com> * Add two more overlay tests * Add ModuleId to OverlayFrame * Fix env conversion accidentally activating overlay It activated overlay from permanent state prematurely which would cause `overlay add` to misbehave. * Remove unused parameter; Add overlay list test * Remove added traces * Add overlay commands examples * Modify TODO * Fix $nu.scope iteration * Disallow removing default overlay * Refactor some parser errors * Remove last overlay if no argument * Diversify overlay examples * Make it possible to update overlay's module In case the origin module updates, the overlay add loads the new module, makes it overlay's origin and applies the changes. Before, it was impossible to update the overlay if the module changed. Co-authored-by: JT <547158+jntrnr@users.noreply.github.com> Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <WindSoilder@outlook.com> Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-07 19:39:22 +00:00
/// Error while trying to read a file
///
/// ## Resolution
///
/// The error will show the result from a file operation
#[error("Error trying to read file")]
remove links to `ShellError` and `ParseError` docs - #8167 (#8193) # Description issue #8167 Remove the `(link)` to the docs for `ShellError` and `ParseError`. As per discussion on the issue, the nu-parser version didn't update on the docs causing deadlinks for those errors, which brought the usefullness of these links into question and it was decided to remove all of them that `derive(diagnostic)`. # User-Facing Changes Before: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter (link) × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` After: ``` /home/rdevenney/projects/open_source/nushell〉ls | get name} Error: nu::parser::unbalanced_delimiter × Unbalanced delimiter. ╭─[entry #1:1:1] 1 │ ls | get name} · ▲ · ╰── unbalanced { and } ╰──── ``` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-24 17:26:31 +00:00
#[diagnostic(code(nu::shell::error_reading_file))]
Overlays (#5375) * WIP: Start laying overlays * Rename Overlay->Module; Start adding overlay * Revamp adding overlay * Add overlay add tests; Disable debug print * Fix overlay add; Add overlay remove * Add overlay remove tests * Add missing overlay remove file * Add overlay list command * (WIP?) Enable overlays for env vars * Move OverlayFrames to ScopeFrames * (WIP) Move everything to overlays only ScopeFrame contains nothing but overlays now * Fix predecls * Fix wrong overlay id translation and aliases * Fix broken env lookup logic * Remove TODOs * Add overlay add + remove for environment * Add a few overlay tests; Fix overlay add name * Some cleanup; Fix overlay add/remove names * Clippy * Fmt * Remove walls of comments * List overlays from stack; Add debugging flag Currently, the engine state ordering is somehow broken. * Fix (?) overlay list test * Fix tests on Windows * Fix activated overlay ordering * Check for active overlays equality in overlay list This removes the -p flag: Either both parser and engine will have the same overlays, or the command will fail. * Add merging on overlay remove * Change help message and comment * Add some remove-merge/discard tests * (WIP) Track removed overlays properly * Clippy; Fmt * Fix getting last overlay; Fix predecls in overlays * Remove merging; Fix re-add overwriting stuff Also some error message tweaks. * Fix overlay error in the engine * Update variable_completions.rs * Adds flags and optional arguments to view-source (#5446) * added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt * fix bug in shell_integration (#5450) * fix bug in shell_integration * add some comments * enable cd to work with directory abbreviations (#5452) * enable cd to work with abbreviations * add abbreviation example * fix tests * make it configurable * make cd recornize symblic link (#5454) * implement seq char command to generate single character sequence (#5453) * add tmp code * add seq char command * Add split number flag in `split row` (#5434) Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com> * Add two more overlay tests * Add ModuleId to OverlayFrame * Fix env conversion accidentally activating overlay It activated overlay from permanent state prematurely which would cause `overlay add` to misbehave. * Remove unused parameter; Add overlay list test * Remove added traces * Add overlay commands examples * Modify TODO * Fix $nu.scope iteration * Disallow removing default overlay * Refactor some parser errors * Remove last overlay if no argument * Diversify overlay examples * Make it possible to update overlay's module In case the origin module updates, the overlay add loads the new module, makes it overlay's origin and applies the changes. Before, it was impossible to update the overlay if the module changed. Co-authored-by: JT <547158+jntrnr@users.noreply.github.com> Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <WindSoilder@outlook.com> Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-07 19:39:22 +00:00
ReadingFile(String, #[label("{0}")] Span),
Syntax errors for string and int (#7952) # Description Added a few syntax errors in ints and strings, changed parser to stop and show that error rather than continue trying to parse those tokens as some other shape. However, I don't see how to push this direction much further, and most of the classic confusing errors can't be changed. Flagged as WIP for the moment, but passes all checks and works better than current release: 1. I have yet to figure out how to make these errors refer back to the book, as I see some other errors do. 2. How to give syntax error when malformed int is first token in line? Currently parsed as external command, user gets confusing error message. 3. Would like to be more strict with *decimal* int literals (lacking, e.g, `0x' prefix). Need to tinker more with the order of parse shape calls, currently, float is tried after int, so '1.4' has to be passed. _(Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience.)_ ```bash 〉"\z" Error: ╭─[entry #3:1:1] 1 │ "\z" · ─┬─ · ╰── Syntax error in string, unrecognized character after escape '\'. ╰──── ``` Canonic presentation of a syntax error. ```bash 〉" \u{01ffbogus}" Error: × Invalid syntax ╭─[entry #2:1:1] 1 │ " \u{01ffbogus}" · ───────┬────── · ╰── Syntax error in string, expecting 1 to 6 hex digits in unicode escape '\u{X...}', max value 10FFFF. ╰──── ``` Malformed unicode escape in string, flagged as error. String parse can be opinionated, it's the last shape tried. ```bash 〉0x22bogus Error: nu::shell::external_command (link) × External command failed ╭─[entry #4:1:1] 1 │ 0x22bogus · ────┬──── · ╰── executable was not found ╰──── help: No such file or directory (os error 2) ``` A *correct* number in first token would be evaluated, but an *incorrect* one is treated as external command? Confusing to users. ```bash 〉0 + 0x22bogus Error: × Invalid syntax ╭─[entry #5:1:1] 1 │ 0 + 0x22bogus · ────┬──── · ╰── Syntax error in int, invalid digits in radix 16 int. ╰──── ``` Can give syntax error if token is unambiguously int literal. e.g has 0b or 0x prefix, could not be a float. ```bash 〉0 + 098bogus Error: nu::parser::unsupported_operation (link) × Types mismatched for operation. ╭─[entry #6:1:1] 1 │ 0 + 098bogus · ┬ ┬ ────┬─── · │ │ ╰── string · │ ╰── doesn't support these values. · ╰── int ╰──── help: Change int or string to be the right types and try again. ``` But *decimal* literal (no prefix) can't be too strict. Parser is going to try float later. So '1.4' must be passed. # User-Facing Changes First and foremost, more specific error messages for typos in string and int literals. Probably improves interactive user experience. But a script that was causing and then checking for specific error might notice a different error message. _(List of all changes that impact the user experience here. This helps us keep track of breaking changes.)_ # Tests + Formatting Added (positive and negative unit tests in `cargo test -p nu-parser`. Didn't add integration tests. Make sure you've run and fixed any issues with these commands: - [x] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - [x] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --------- Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2023-02-13 16:09:50 +00:00
#[error("Invalid literal")] // <problem> in <entity>.
#[diagnostic()]
InvalidLiteral(String, String, #[label("{0} in {1}")] Span),
#[error("{0}")]
#[diagnostic()]
LabeledError(String, String, #[label("{1}")] Span),
#[error("{error}")]
#[diagnostic(help("{help}"))]
LabeledErrorWithHelp {
error: String,
label: String,
help: String,
#[label("{label}")]
span: Span,
},
#[error("Redirection can not be used with let/mut.")]
#[diagnostic()]
RedirectionInLetMut(
#[label("Not allowed here")] Span,
#[label("...and here")] Option<Span>,
),
Allow spreading arguments to commands (#11289) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> Finishes implementing https://github.com/nushell/nushell/issues/10598, which asks for a spread operator in lists, in records, and when calling commands. # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR will allow spreading arguments to commands (both internal and external). It will also deprecate spreading arguments automatically when passing to external commands. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> - Users will be able to use `...` to spread arguments to custom/builtin commands that have rest parameters or allow unknown arguments, or to any external command - If a custom command doesn't have a rest parameter and it doesn't allow unknown arguments either, the spread operator will not be allowed - Passing lists to external commands without `...` will work for now but will cause a deprecation warning saying that it'll stop working in 0.91 (is 2 versions enough time?) Here's a function to help with demonstrating some behavior: ```nushell > def foo [ a, b, c?, d?, ...rest ] { [$a $b $c $d $rest] | to nuon } ``` You can pass a list of arguments to fill in the `rest` parameter using `...`: ```nushell > foo 1 2 3 4 ...[5 6] [1, 2, 3, 4, [5, 6]] ``` If you don't use `...`, the list `[5 6]` will be treated as a single argument: ```nushell > foo 1 2 3 4 [5 6] # Note the double [[]] [1, 2, 3, 4, [[5, 6]]] ``` You can omit optional parameters before the spread arguments: ```nushell > foo 1 2 3 ...[4 5] # d is omitted here [1, 2, 3, null, [4, 5]] ``` If you have multiple lists, you can spread them all: ```nushell > foo 1 2 3 ...[4 5] 6 7 ...[8] ...[] [1, 2, 3, null, [4, 5, 6, 7, 8]] ``` Here's the kind of error you get when you try to spread arguments to a command with no rest parameter: ![image](https://github.com/nushell/nushell/assets/45539777/93faceae-00eb-4e59-ac3f-17f98436e6e4) And this is the warning you get when you pass a list to an external now (without `...`): ![image](https://github.com/nushell/nushell/assets/45539777/d368f590-201e-49fb-8b20-68476ced415e) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Added tests to cover the following cases: - Spreading arguments to a command that doesn't have a rest parameter (unexpected spread argument error) - Spreading arguments to a command that doesn't have a rest parameter *but* there's also a missing positional argument (missing positional error) - Spreading arguments to a command that doesn't have a rest parameter but does allow unknown arguments, such as `exec` (allowed) - Spreading a list literal containing arguments of the wrong type (parse error) - Spreading a non-list value, both to internal and external commands - Having named arguments in the middle of rest arguments - `explain`ing a command call that spreads its arguments # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> # Examples Suppose you have multiple tables: ```nushell let people = [[id name age]; [0 alice 100] [1 bob 200] [2 eve 300]] let evil_twins = [[id name age]; [0 ecila 100] [-1 bob 200] [-2 eve 300]] ``` Maybe you often find yourself needing to merge multiple tables and want a utility to do that. You could write a function like this: ```nushell def merge_all [ ...tables ] { $tables | reduce { |it, acc| $acc | merge $it } } ``` Then you can use it like this: ```nushell > merge_all ...([$people $evil_twins] | each { |$it| $it | select name age }) ╭───┬───────┬─────╮ │ # │ name │ age │ ├───┼───────┼─────┤ │ 0 │ ecila │ 100 │ │ 1 │ bob │ 200 │ │ 2 │ eve │ 300 │ ╰───┴───────┴─────╯ ``` Except they had duplicate columns, so now you first want to suffix every column with a number to tell you which table the column came from. You can make a command for that: ```nushell def select_and_merge [ --cols: list<string>, ...tables ] { let renamed_tables = $tables | enumerate | each { |it| $it.item | select $cols | rename ...($cols | each { |col| $col + ($it.index | into string) }) }; merge_all ...$renamed_tables } ``` And call it like this: ```nushell > select_and_merge --cols [name age] $people $evil_twins ╭───┬───────┬──────┬───────┬──────╮ │ # │ name0 │ age0 │ name1 │ age1 │ ├───┼───────┼──────┼───────┼──────┤ │ 0 │ alice │ 100 │ ecila │ 100 │ │ 1 │ bob │ 200 │ bob │ 200 │ │ 2 │ eve │ 300 │ eve │ 300 │ ╰───┴───────┴──────┴───────┴──────╯ ``` --- Suppose someone's made a command to search for APT packages: ```nushell # The main command def search-pkgs [ --install # Whether to install any packages it finds log_level: int # Pretend it's a good idea to make this a required positional parameter exclude?: list<string> # Packages to exclude repositories?: list<string> # Which repositories to look in (searches in all if not given) ...pkgs # Package names to search for ] { { install: $install, log_level: $log_level, exclude: ($exclude | to nuon), repositories: ($repositories | to nuon), pkgs: ($pkgs | to nuon) } } ``` It has a lot of parameters to configure it, so you might make your own helper commands to wrap around it for specific cases. Here's one example: ```nushell # Only look for packages locally def search-pkgs-local [ --install # Whether to install any packages it finds log_level: int exclude?: list<string> # Packages to exclude ...pkgs # Package names to search for ] { # All required and optional positional parameters are given search-pkgs --install=$install $log_level [] ["<local URI or something>"] ...$pkgs } ``` And you can run it like this: ```nushell > search-pkgs-local --install=false 5 ...["python2.7" "vim"] ╭──────────────┬──────────────────────────────╮ │ install │ false │ │ log_level │ 5 │ │ exclude │ [] │ │ repositories │ ["<local URI or something>"] │ │ pkgs │ ["python2.7", vim] │ ╰──────────────┴──────────────────────────────╯ ``` One thing I realized when writing this was that if we decide to not allow passing optional arguments using the spread operator, then you can (mis?)use the spread operator to skip optional parameters. Here, I didn't want to give `exclude` explicitly, so I used a spread operator to pass the packages to install. Without it, I would've needed to do `search-pkgs-local --install=false 5 [] "python2.7" "vim"` (explicitly pass `[]` (or `null`, in the general case) to `exclude`). There are probably more idiomatic ways to do this, but I just thought it was something interesting. If you're a virologist of the [xkcd](https://xkcd.com/350/) kind, another helper command you might make is this: ```nushell # Install any packages it finds def live-dangerously [ ...pkgs ] { # One optional argument was given (exclude), while another was not (repositories) search-pkgs 0 [] ...$pkgs --install # Flags can go after spread arguments } ``` Running it: ```nushell > live-dangerously "git" "*vi*" # *vi* because I don't feel like typing out vim and neovim ╭──────────────┬─────────────╮ │ install │ true │ │ log_level │ 0 │ │ exclude │ [] │ │ repositories │ null │ │ pkgs │ [git, *vi*] │ ╰──────────────┴─────────────╯ ``` Here's an example that uses the spread operator more than once within the same command call: ```nushell let extras = [ chrome firefox python java git ] def search-pkgs-curated [ ...pkgs ] { (search-pkgs 1 [emacs] ["example.com", "foo.com"] vim # A must for everyone! ...($pkgs | filter { |p| not ($p | str contains "*") }) # Remove packages with globs python # Good tool to have ...$extras --install=false python3) # I forget, did I already put Python in extras? } ``` Running it: ```nushell > search-pkgs-curated "git" "*vi*" ╭──────────────┬───────────────────────────────────────────────────────────────────╮ │ install │ false │ │ log_level │ 1 │ │ exclude │ [emacs] │ │ repositories │ [example.com, foo.com] │ │ pkgs │ [vim, git, python, chrome, firefox, python, java, git, "python3"] │ ╰──────────────┴───────────────────────────────────────────────────────────────────╯ ```
2023-12-28 07:43:20 +00:00
#[error("This command does not have a ...rest parameter")]
#[diagnostic(
code(nu::parser::unexpected_spread_arg),
help("To spread arguments, the command needs to define a multi-positional parameter in its signature, such as ...rest")
)]
UnexpectedSpreadArg(String, #[label = "unexpected spread argument"] Span),
2021-08-16 23:00:00 +00:00
}
impl ParseError {
pub fn span(&self) -> Span {
match self {
ParseError::ExtraTokens(s) => *s,
ParseError::ExtraPositional(_, s) => *s,
ParseError::UnexpectedEof(_, s) => *s,
ParseError::Unclosed(_, s) => *s,
ParseError::Unbalanced(_, _, s) => *s,
ParseError::Expected(_, s) => *s,
ParseError::ExpectedWithStringMsg(_, s) => *s,
ParseError::Mismatch(_, _, s) => *s,
improve operation mismatch errors (#8800) # Description This improves the operation mismatch error in a few ways: * We now detect if the left-hand side of the operation is at fault, and show a simpler error/error message if it is * Removed the unhelpful hint * Updated the error text to make it clear what types are causing the issue ![image](https://user-images.githubusercontent.com/547158/230666329-537a8cae-6350-4ee7-878e-777e05c4f265.png) ![image](https://user-images.githubusercontent.com/547158/230666353-93529dc2-039a-4774-a84c-a6faac94d8e2.png) # User-Facing Changes Error texts and spans will change # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-utils/standard_library/tests.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-04-07 21:32:44 +00:00
ParseError::UnsupportedOperationLHS(_, _, s, _) => *s,
ParseError::UnsupportedOperationRHS(_, _, _, _, s, _) => *s,
ParseError::ExpectedKeyword(_, s) => *s,
ParseError::UnexpectedKeyword(_, s) => *s,
2023-03-10 21:20:31 +00:00
ParseError::CantAliasKeyword(_, s) => *s,
ParseError::CantAliasExpression(_, s) => *s,
ParseError::BuiltinCommandInPipeline(_, s) => *s,
ParseError::AssignInPipeline(_, _, _, s) => *s,
ParseError::NameIsBuiltinVar(_, s) => *s,
ParseError::CaptureOfMutableVar(s) => *s,
ParseError::IncorrectValue(_, s, _) => *s,
ParseError::MultipleRestParams(s) => *s,
ParseError::VariableNotFound(_, s) => *s,
Better error message if env var is used as var (#9522) # Description This PR improves the error message if an environment variable (that's visible before the parser begins) is used in the form of `$PATH` instead of `$env.PATH`. Before: ``` Error: nu::parser::variable_not_found × Variable not found. ╭─[entry #31:1:1] 1 │ echo $PATH · ──┬── · ╰── variable not found. ╰──── ``` After: ``` Error: nu::parser::env_var_not_var × Use $env.PATH instead of $PATH. ╭─[entry #1:1:1] 1 │ echo $PATH · ──┬── · ╰── use $env.PATH instead of $PATH ╰──── ``` # User-Facing Changes Just the improvement to the error message # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-06-25 17:59:56 +00:00
ParseError::EnvVarNotVar(_, s) => *s,
ParseError::VariableNotValid(s) => *s,
ParseError::AliasNotValid(s) => *s,
ParseError::CommandDefNotValid(s) => *s,
ParseError::ModuleNotFound(s) => *s,
ParseError::ModuleMissingModNuFile(_, s) => *s,
ParseError::NamedAsModule(_, _, _, s) => *s,
ParseError::ModuleDoubleMain(_, s) => *s,
ParseError::InvalidModuleFileName(_, _, s) => *s,
ParseError::ExportMainAliasNotAllowed(s) => *s,
ParseError::CyclicalModuleImport(_, s) => *s,
Overlays (#5375) * WIP: Start laying overlays * Rename Overlay->Module; Start adding overlay * Revamp adding overlay * Add overlay add tests; Disable debug print * Fix overlay add; Add overlay remove * Add overlay remove tests * Add missing overlay remove file * Add overlay list command * (WIP?) Enable overlays for env vars * Move OverlayFrames to ScopeFrames * (WIP) Move everything to overlays only ScopeFrame contains nothing but overlays now * Fix predecls * Fix wrong overlay id translation and aliases * Fix broken env lookup logic * Remove TODOs * Add overlay add + remove for environment * Add a few overlay tests; Fix overlay add name * Some cleanup; Fix overlay add/remove names * Clippy * Fmt * Remove walls of comments * List overlays from stack; Add debugging flag Currently, the engine state ordering is somehow broken. * Fix (?) overlay list test * Fix tests on Windows * Fix activated overlay ordering * Check for active overlays equality in overlay list This removes the -p flag: Either both parser and engine will have the same overlays, or the command will fail. * Add merging on overlay remove * Change help message and comment * Add some remove-merge/discard tests * (WIP) Track removed overlays properly * Clippy; Fmt * Fix getting last overlay; Fix predecls in overlays * Remove merging; Fix re-add overwriting stuff Also some error message tweaks. * Fix overlay error in the engine * Update variable_completions.rs * Adds flags and optional arguments to view-source (#5446) * added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt * fix bug in shell_integration (#5450) * fix bug in shell_integration * add some comments * enable cd to work with directory abbreviations (#5452) * enable cd to work with abbreviations * add abbreviation example * fix tests * make it configurable * make cd recornize symblic link (#5454) * implement seq char command to generate single character sequence (#5453) * add tmp code * add seq char command * Add split number flag in `split row` (#5434) Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com> * Add two more overlay tests * Add ModuleId to OverlayFrame * Fix env conversion accidentally activating overlay It activated overlay from permanent state prematurely which would cause `overlay add` to misbehave. * Remove unused parameter; Add overlay list test * Remove added traces * Add overlay commands examples * Modify TODO * Fix $nu.scope iteration * Disallow removing default overlay * Refactor some parser errors * Remove last overlay if no argument * Diversify overlay examples * Make it possible to update overlay's module In case the origin module updates, the overlay add loads the new module, makes it overlay's origin and applies the changes. Before, it was impossible to update the overlay if the module changed. Co-authored-by: JT <547158+jntrnr@users.noreply.github.com> Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <WindSoilder@outlook.com> Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-07 19:39:22 +00:00
ParseError::ModuleOrOverlayNotFound(s) => *s,
ParseError::ActiveOverlayNotFound(s) => *s,
ParseError::OverlayPrefixMismatch(_, _, s) => *s,
Overlays (#5375) * WIP: Start laying overlays * Rename Overlay->Module; Start adding overlay * Revamp adding overlay * Add overlay add tests; Disable debug print * Fix overlay add; Add overlay remove * Add overlay remove tests * Add missing overlay remove file * Add overlay list command * (WIP?) Enable overlays for env vars * Move OverlayFrames to ScopeFrames * (WIP) Move everything to overlays only ScopeFrame contains nothing but overlays now * Fix predecls * Fix wrong overlay id translation and aliases * Fix broken env lookup logic * Remove TODOs * Add overlay add + remove for environment * Add a few overlay tests; Fix overlay add name * Some cleanup; Fix overlay add/remove names * Clippy * Fmt * Remove walls of comments * List overlays from stack; Add debugging flag Currently, the engine state ordering is somehow broken. * Fix (?) overlay list test * Fix tests on Windows * Fix activated overlay ordering * Check for active overlays equality in overlay list This removes the -p flag: Either both parser and engine will have the same overlays, or the command will fail. * Add merging on overlay remove * Change help message and comment * Add some remove-merge/discard tests * (WIP) Track removed overlays properly * Clippy; Fmt * Fix getting last overlay; Fix predecls in overlays * Remove merging; Fix re-add overwriting stuff Also some error message tweaks. * Fix overlay error in the engine * Update variable_completions.rs * Adds flags and optional arguments to view-source (#5446) * added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt * fix bug in shell_integration (#5450) * fix bug in shell_integration * add some comments * enable cd to work with directory abbreviations (#5452) * enable cd to work with abbreviations * add abbreviation example * fix tests * make it configurable * make cd recornize symblic link (#5454) * implement seq char command to generate single character sequence (#5453) * add tmp code * add seq char command * Add split number flag in `split row` (#5434) Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com> * Add two more overlay tests * Add ModuleId to OverlayFrame * Fix env conversion accidentally activating overlay It activated overlay from permanent state prematurely which would cause `overlay add` to misbehave. * Remove unused parameter; Add overlay list test * Remove added traces * Add overlay commands examples * Modify TODO * Fix $nu.scope iteration * Disallow removing default overlay * Refactor some parser errors * Remove last overlay if no argument * Diversify overlay examples * Make it possible to update overlay's module In case the origin module updates, the overlay add loads the new module, makes it overlay's origin and applies the changes. Before, it was impossible to update the overlay if the module changed. Co-authored-by: JT <547158+jntrnr@users.noreply.github.com> Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <WindSoilder@outlook.com> Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-07 19:39:22 +00:00
ParseError::CantRemoveLastOverlay(s) => *s,
ParseError::CantHideDefaultOverlay(_, s) => *s,
ParseError::CantAddOverlayHelp(_, s) => *s,
ParseError::NotFound(s) => *s,
ParseError::DuplicateCommandDef(s) => *s,
ParseError::UnknownCommand(s) => *s,
ParseError::NonUtf8(s) => *s,
ParseError::UnknownFlag(_, _, s, _) => *s,
2022-03-07 20:08:56 +00:00
ParseError::RequiredAfterOptional(_, s) => *s,
ParseError::UnknownType(s) => *s,
ParseError::MissingFlagParam(_, s) => *s,
ParseError::OnlyLastFlagInBatchCanTakeArg(s) => *s,
ParseError::MissingPositional(_, s, _) => *s,
ParseError::KeywordMissingArgument(_, _, s) => *s,
ParseError::MissingType(s) => *s,
ParseError::TypeMismatch(_, _, s) => *s,
ParseError::TypeMismatchHelp(_, _, s, _) => *s,
Input output checking (#9680) # Description This PR tights input/output type-checking a bit more. There are a lot of commands that don't have correct input/output types, so part of the effort is updating them. This PR now contains updates to commands that had wrong input/output signatures. It doesn't add examples for these new signatures, but that can be follow-up work. # User-Facing Changes BREAKING CHANGE BREAKING CHANGE This work enforces many more checks on pipeline type correctness than previous nushell versions. This strictness may uncover incompatibilities in existing scripts or shortcomings in the type information for internal commands. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-07-14 03:20:35 +00:00
ParseError::InputMismatch(_, s) => *s,
ParseError::OutputMismatch(_, s) => *s,
ParseError::MissingRequiredFlag(_, s) => *s,
ParseError::IncompleteMathExpression(s) => *s,
ParseError::UnknownState(_, s) => *s,
ParseError::InternalError(_, s) => *s,
ParseError::IncompleteParser(s) => *s,
ParseError::RestNeedsName(s) => *s,
ParseError::ParameterMismatchType(_, _, _, s) => *s,
ParseError::NonConstantDefaultValue(s) => *s,
ParseError::ExtraColumns(_, s) => *s,
ParseError::MissingColumns(_, s) => *s,
ParseError::AssignmentMismatch(_, _, s) => *s,
ParseError::MissingImportPattern(s) => *s,
ParseError::WrongImportPattern(_, s) => *s,
ParseError::ExportNotFound(s) => *s,
ParseError::SourcedFileNotFound(_, s) => *s,
ParseError::RegisteredFileNotFound(_, s) => *s,
ParseError::FileNotFound(_, s) => *s,
Overlays (#5375) * WIP: Start laying overlays * Rename Overlay->Module; Start adding overlay * Revamp adding overlay * Add overlay add tests; Disable debug print * Fix overlay add; Add overlay remove * Add overlay remove tests * Add missing overlay remove file * Add overlay list command * (WIP?) Enable overlays for env vars * Move OverlayFrames to ScopeFrames * (WIP) Move everything to overlays only ScopeFrame contains nothing but overlays now * Fix predecls * Fix wrong overlay id translation and aliases * Fix broken env lookup logic * Remove TODOs * Add overlay add + remove for environment * Add a few overlay tests; Fix overlay add name * Some cleanup; Fix overlay add/remove names * Clippy * Fmt * Remove walls of comments * List overlays from stack; Add debugging flag Currently, the engine state ordering is somehow broken. * Fix (?) overlay list test * Fix tests on Windows * Fix activated overlay ordering * Check for active overlays equality in overlay list This removes the -p flag: Either both parser and engine will have the same overlays, or the command will fail. * Add merging on overlay remove * Change help message and comment * Add some remove-merge/discard tests * (WIP) Track removed overlays properly * Clippy; Fmt * Fix getting last overlay; Fix predecls in overlays * Remove merging; Fix re-add overwriting stuff Also some error message tweaks. * Fix overlay error in the engine * Update variable_completions.rs * Adds flags and optional arguments to view-source (#5446) * added flags and optional arguments to view-source * removed redundant code * removed redundant code * fmt * fix bug in shell_integration (#5450) * fix bug in shell_integration * add some comments * enable cd to work with directory abbreviations (#5452) * enable cd to work with abbreviations * add abbreviation example * fix tests * make it configurable * make cd recornize symblic link (#5454) * implement seq char command to generate single character sequence (#5453) * add tmp code * add seq char command * Add split number flag in `split row` (#5434) Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com> * Add two more overlay tests * Add ModuleId to OverlayFrame * Fix env conversion accidentally activating overlay It activated overlay from permanent state prematurely which would cause `overlay add` to misbehave. * Remove unused parameter; Add overlay list test * Remove added traces * Add overlay commands examples * Modify TODO * Fix $nu.scope iteration * Disallow removing default overlay * Refactor some parser errors * Remove last overlay if no argument * Diversify overlay examples * Make it possible to update overlay's module In case the origin module updates, the overlay add loads the new module, makes it overlay's origin and applies the changes. Before, it was impossible to update the overlay if the module changed. Co-authored-by: JT <547158+jntrnr@users.noreply.github.com> Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <WindSoilder@outlook.com> Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
2022-05-07 19:39:22 +00:00
ParseError::ReadingFile(_, s) => *s,
ParseError::LabeledError(_, _, s) => *s,
Better errors when bash-like operators are used (#7241) # Description Adds improved errors for when a user uses a bashism that nu doesn't support. fixes #7237 Examples: ``` Error: nu::parser::shell_andand (link) × The '&&' operator is not supported in Nushell ╭─[entry #1:1:1] 1 │ ls && ls · ─┬ · ╰── instead of '&&', use ';' or 'and' ╰──── help: use ';' instead of the shell '&&', or 'and' instead of the boolean '&&' ``` ``` Error: nu::parser::shell_oror (link) × The '||' operator is not supported in Nushell ╭─[entry #8:1:1] 1 │ ls || ls · ─┬ · ╰── instead of '||', use 'try' or 'or' ╰──── help: use 'try' instead of the shell '||', or 'or' instead of the boolean '||' ``` ``` Error: nu::parser::shell_err (link) × The '2>' shell operation is 'err>' in Nushell. ╭─[entry #9:1:1] 1 │ foo 2> bar.txt · ─┬ · ╰── use 'err>' instead of '2>' in Nushell ╰──── ``` ``` Error: nu::parser::shell_outerr (link) × The '2>&1' shell operation is 'out+err>' in Nushell. ╭─[entry #10:1:1] 1 │ foo 2>&1 bar.txt · ──┬─ · ╰── use 'out+err>' instead of '2>&1' in Nushell ╰──── help: Nushell redirection will write all of stdout before stderr. ``` # User-Facing Changes **BREAKING CHANGES** This removes the `&&` and `||` operators. We previously supported by `&&`/`and` and `||`/`or`. With this change, only `and` and `or` are valid boolean operators. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2022-12-07 23:02:11 +00:00
ParseError::ShellAndAnd(s) => *s,
ParseError::ShellOrOr(s) => *s,
ParseError::ShellErrRedirect(s) => *s,
ParseError::ShellOutErrRedirect(s) => *s,
ParseError::UnknownOperator(_, _, s) => *s,
Syntax errors for string and int (#7952) # Description Added a few syntax errors in ints and strings, changed parser to stop and show that error rather than continue trying to parse those tokens as some other shape. However, I don't see how to push this direction much further, and most of the classic confusing errors can't be changed. Flagged as WIP for the moment, but passes all checks and works better than current release: 1. I have yet to figure out how to make these errors refer back to the book, as I see some other errors do. 2. How to give syntax error when malformed int is first token in line? Currently parsed as external command, user gets confusing error message. 3. Would like to be more strict with *decimal* int literals (lacking, e.g, `0x' prefix). Need to tinker more with the order of parse shape calls, currently, float is tried after int, so '1.4' has to be passed. _(Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience.)_ ```bash 〉"\z" Error: ╭─[entry #3:1:1] 1 │ "\z" · ─┬─ · ╰── Syntax error in string, unrecognized character after escape '\'. ╰──── ``` Canonic presentation of a syntax error. ```bash 〉" \u{01ffbogus}" Error: × Invalid syntax ╭─[entry #2:1:1] 1 │ " \u{01ffbogus}" · ───────┬────── · ╰── Syntax error in string, expecting 1 to 6 hex digits in unicode escape '\u{X...}', max value 10FFFF. ╰──── ``` Malformed unicode escape in string, flagged as error. String parse can be opinionated, it's the last shape tried. ```bash 〉0x22bogus Error: nu::shell::external_command (link) × External command failed ╭─[entry #4:1:1] 1 │ 0x22bogus · ────┬──── · ╰── executable was not found ╰──── help: No such file or directory (os error 2) ``` A *correct* number in first token would be evaluated, but an *incorrect* one is treated as external command? Confusing to users. ```bash 〉0 + 0x22bogus Error: × Invalid syntax ╭─[entry #5:1:1] 1 │ 0 + 0x22bogus · ────┬──── · ╰── Syntax error in int, invalid digits in radix 16 int. ╰──── ``` Can give syntax error if token is unambiguously int literal. e.g has 0b or 0x prefix, could not be a float. ```bash 〉0 + 098bogus Error: nu::parser::unsupported_operation (link) × Types mismatched for operation. ╭─[entry #6:1:1] 1 │ 0 + 098bogus · ┬ ┬ ────┬─── · │ │ ╰── string · │ ╰── doesn't support these values. · ╰── int ╰──── help: Change int or string to be the right types and try again. ``` But *decimal* literal (no prefix) can't be too strict. Parser is going to try float later. So '1.4' must be passed. # User-Facing Changes First and foremost, more specific error messages for typos in string and int literals. Probably improves interactive user experience. But a script that was causing and then checking for specific error might notice a different error message. _(List of all changes that impact the user experience here. This helps us keep track of breaking changes.)_ # Tests + Formatting Added (positive and negative unit tests in `cargo test -p nu-parser`. Didn't add integration tests. Make sure you've run and fixed any issues with these commands: - [x] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - [x] `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --------- Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2023-02-13 16:09:50 +00:00
ParseError::InvalidLiteral(_, _, s) => *s,
ParseError::LabeledErrorWithHelp { span: s, .. } => *s,
ParseError::RedirectionInLetMut(s, _) => *s,
Allow spreading arguments to commands (#11289) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> Finishes implementing https://github.com/nushell/nushell/issues/10598, which asks for a spread operator in lists, in records, and when calling commands. # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR will allow spreading arguments to commands (both internal and external). It will also deprecate spreading arguments automatically when passing to external commands. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> - Users will be able to use `...` to spread arguments to custom/builtin commands that have rest parameters or allow unknown arguments, or to any external command - If a custom command doesn't have a rest parameter and it doesn't allow unknown arguments either, the spread operator will not be allowed - Passing lists to external commands without `...` will work for now but will cause a deprecation warning saying that it'll stop working in 0.91 (is 2 versions enough time?) Here's a function to help with demonstrating some behavior: ```nushell > def foo [ a, b, c?, d?, ...rest ] { [$a $b $c $d $rest] | to nuon } ``` You can pass a list of arguments to fill in the `rest` parameter using `...`: ```nushell > foo 1 2 3 4 ...[5 6] [1, 2, 3, 4, [5, 6]] ``` If you don't use `...`, the list `[5 6]` will be treated as a single argument: ```nushell > foo 1 2 3 4 [5 6] # Note the double [[]] [1, 2, 3, 4, [[5, 6]]] ``` You can omit optional parameters before the spread arguments: ```nushell > foo 1 2 3 ...[4 5] # d is omitted here [1, 2, 3, null, [4, 5]] ``` If you have multiple lists, you can spread them all: ```nushell > foo 1 2 3 ...[4 5] 6 7 ...[8] ...[] [1, 2, 3, null, [4, 5, 6, 7, 8]] ``` Here's the kind of error you get when you try to spread arguments to a command with no rest parameter: ![image](https://github.com/nushell/nushell/assets/45539777/93faceae-00eb-4e59-ac3f-17f98436e6e4) And this is the warning you get when you pass a list to an external now (without `...`): ![image](https://github.com/nushell/nushell/assets/45539777/d368f590-201e-49fb-8b20-68476ced415e) # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> Added tests to cover the following cases: - Spreading arguments to a command that doesn't have a rest parameter (unexpected spread argument error) - Spreading arguments to a command that doesn't have a rest parameter *but* there's also a missing positional argument (missing positional error) - Spreading arguments to a command that doesn't have a rest parameter but does allow unknown arguments, such as `exec` (allowed) - Spreading a list literal containing arguments of the wrong type (parse error) - Spreading a non-list value, both to internal and external commands - Having named arguments in the middle of rest arguments - `explain`ing a command call that spreads its arguments # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> # Examples Suppose you have multiple tables: ```nushell let people = [[id name age]; [0 alice 100] [1 bob 200] [2 eve 300]] let evil_twins = [[id name age]; [0 ecila 100] [-1 bob 200] [-2 eve 300]] ``` Maybe you often find yourself needing to merge multiple tables and want a utility to do that. You could write a function like this: ```nushell def merge_all [ ...tables ] { $tables | reduce { |it, acc| $acc | merge $it } } ``` Then you can use it like this: ```nushell > merge_all ...([$people $evil_twins] | each { |$it| $it | select name age }) ╭───┬───────┬─────╮ │ # │ name │ age │ ├───┼───────┼─────┤ │ 0 │ ecila │ 100 │ │ 1 │ bob │ 200 │ │ 2 │ eve │ 300 │ ╰───┴───────┴─────╯ ``` Except they had duplicate columns, so now you first want to suffix every column with a number to tell you which table the column came from. You can make a command for that: ```nushell def select_and_merge [ --cols: list<string>, ...tables ] { let renamed_tables = $tables | enumerate | each { |it| $it.item | select $cols | rename ...($cols | each { |col| $col + ($it.index | into string) }) }; merge_all ...$renamed_tables } ``` And call it like this: ```nushell > select_and_merge --cols [name age] $people $evil_twins ╭───┬───────┬──────┬───────┬──────╮ │ # │ name0 │ age0 │ name1 │ age1 │ ├───┼───────┼──────┼───────┼──────┤ │ 0 │ alice │ 100 │ ecila │ 100 │ │ 1 │ bob │ 200 │ bob │ 200 │ │ 2 │ eve │ 300 │ eve │ 300 │ ╰───┴───────┴──────┴───────┴──────╯ ``` --- Suppose someone's made a command to search for APT packages: ```nushell # The main command def search-pkgs [ --install # Whether to install any packages it finds log_level: int # Pretend it's a good idea to make this a required positional parameter exclude?: list<string> # Packages to exclude repositories?: list<string> # Which repositories to look in (searches in all if not given) ...pkgs # Package names to search for ] { { install: $install, log_level: $log_level, exclude: ($exclude | to nuon), repositories: ($repositories | to nuon), pkgs: ($pkgs | to nuon) } } ``` It has a lot of parameters to configure it, so you might make your own helper commands to wrap around it for specific cases. Here's one example: ```nushell # Only look for packages locally def search-pkgs-local [ --install # Whether to install any packages it finds log_level: int exclude?: list<string> # Packages to exclude ...pkgs # Package names to search for ] { # All required and optional positional parameters are given search-pkgs --install=$install $log_level [] ["<local URI or something>"] ...$pkgs } ``` And you can run it like this: ```nushell > search-pkgs-local --install=false 5 ...["python2.7" "vim"] ╭──────────────┬──────────────────────────────╮ │ install │ false │ │ log_level │ 5 │ │ exclude │ [] │ │ repositories │ ["<local URI or something>"] │ │ pkgs │ ["python2.7", vim] │ ╰──────────────┴──────────────────────────────╯ ``` One thing I realized when writing this was that if we decide to not allow passing optional arguments using the spread operator, then you can (mis?)use the spread operator to skip optional parameters. Here, I didn't want to give `exclude` explicitly, so I used a spread operator to pass the packages to install. Without it, I would've needed to do `search-pkgs-local --install=false 5 [] "python2.7" "vim"` (explicitly pass `[]` (or `null`, in the general case) to `exclude`). There are probably more idiomatic ways to do this, but I just thought it was something interesting. If you're a virologist of the [xkcd](https://xkcd.com/350/) kind, another helper command you might make is this: ```nushell # Install any packages it finds def live-dangerously [ ...pkgs ] { # One optional argument was given (exclude), while another was not (repositories) search-pkgs 0 [] ...$pkgs --install # Flags can go after spread arguments } ``` Running it: ```nushell > live-dangerously "git" "*vi*" # *vi* because I don't feel like typing out vim and neovim ╭──────────────┬─────────────╮ │ install │ true │ │ log_level │ 0 │ │ exclude │ [] │ │ repositories │ null │ │ pkgs │ [git, *vi*] │ ╰──────────────┴─────────────╯ ``` Here's an example that uses the spread operator more than once within the same command call: ```nushell let extras = [ chrome firefox python java git ] def search-pkgs-curated [ ...pkgs ] { (search-pkgs 1 [emacs] ["example.com", "foo.com"] vim # A must for everyone! ...($pkgs | filter { |p| not ($p | str contains "*") }) # Remove packages with globs python # Good tool to have ...$extras --install=false python3) # I forget, did I already put Python in extras? } ``` Running it: ```nushell > search-pkgs-curated "git" "*vi*" ╭──────────────┬───────────────────────────────────────────────────────────────────╮ │ install │ false │ │ log_level │ 1 │ │ exclude │ [emacs] │ │ repositories │ [example.com, foo.com] │ │ pkgs │ [vim, git, python, chrome, firefox, python, java, git, "python3"] │ ╰──────────────┴───────────────────────────────────────────────────────────────────╯ ```
2023-12-28 07:43:20 +00:00
ParseError::UnexpectedSpreadArg(_, s) => *s,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DidYouMean(Option<String>);
fn did_you_mean_impl(possibilities_bytes: &[&[u8]], input_bytes: &[u8]) -> Option<String> {
let input = from_utf8(input_bytes).ok()?;
let possibilities = possibilities_bytes
.iter()
.map(|p| from_utf8(p))
.collect::<Result<Vec<&str>, Utf8Error>>()
.ok()?;
did_you_mean(&possibilities, input)
}
impl DidYouMean {
pub fn new(possibilities_bytes: &[&[u8]], input_bytes: &[u8]) -> DidYouMean {
DidYouMean(did_you_mean_impl(possibilities_bytes, input_bytes))
}
}
impl From<Option<String>> for DidYouMean {
fn from(value: Option<String>) -> Self {
Self(value)
}
}
impl Display for DidYouMean {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(suggestion) = &self.0 {
write!(f, "Did you mean '{}'?", suggestion)
} else {
write!(f, "")
}
}
}