mirror of
https://github.com/nushell/nushell.git
synced 2024-11-28 19:33:47 +01:00
Exposed the recursion limit value as a config option (#12308)
<!-- 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. --> Closes #12253. Exposes the option as "recursion_limit" under config. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> The config file now has a new option! # 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. --> Nothing else...? Do let me know if there's something I've missed!
This commit is contained in:
parent
8e763a2fd6
commit
04531357b4
@ -47,12 +47,12 @@ pub fn eval_call<D: DebugContext>(
|
|||||||
// To prevent a stack overflow in user code from crashing the shell,
|
// To prevent a stack overflow in user code from crashing the shell,
|
||||||
// we limit the recursion depth of function calls.
|
// we limit the recursion depth of function calls.
|
||||||
// Picked 50 arbitrarily, should work on all architectures.
|
// Picked 50 arbitrarily, should work on all architectures.
|
||||||
const MAXIMUM_CALL_STACK_DEPTH: u64 = 50;
|
let maximum_call_stack_depth: u64 = engine_state.config.recursion_limit as u64;
|
||||||
callee_stack.recursion_count += 1;
|
callee_stack.recursion_count += 1;
|
||||||
if callee_stack.recursion_count > MAXIMUM_CALL_STACK_DEPTH {
|
if callee_stack.recursion_count > maximum_call_stack_depth {
|
||||||
callee_stack.recursion_count = 0;
|
callee_stack.recursion_count = 0;
|
||||||
return Err(ShellError::RecursionLimitReached {
|
return Err(ShellError::RecursionLimitReached {
|
||||||
recursion_limit: MAXIMUM_CALL_STACK_DEPTH,
|
recursion_limit: maximum_call_stack_depth,
|
||||||
span: block.span,
|
span: block.span,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ pub struct Config {
|
|||||||
pub footer_mode: FooterMode,
|
pub footer_mode: FooterMode,
|
||||||
pub float_precision: i64,
|
pub float_precision: i64,
|
||||||
pub max_external_completion_results: i64,
|
pub max_external_completion_results: i64,
|
||||||
|
pub recursion_limit: i64,
|
||||||
pub filesize_format: String,
|
pub filesize_format: String,
|
||||||
pub use_ansi_coloring: bool,
|
pub use_ansi_coloring: bool,
|
||||||
pub quick_completions: bool,
|
pub quick_completions: bool,
|
||||||
@ -133,6 +134,7 @@ impl Default for Config {
|
|||||||
completion_algorithm: CompletionAlgorithm::default(),
|
completion_algorithm: CompletionAlgorithm::default(),
|
||||||
enable_external_completion: true,
|
enable_external_completion: true,
|
||||||
max_external_completion_results: 100,
|
max_external_completion_results: 100,
|
||||||
|
recursion_limit: 50,
|
||||||
external_completer: None,
|
external_completer: None,
|
||||||
use_ls_colors_completions: true,
|
use_ls_colors_completions: true,
|
||||||
|
|
||||||
@ -753,6 +755,19 @@ impl Value {
|
|||||||
value,
|
value,
|
||||||
&mut errors);
|
&mut errors);
|
||||||
}
|
}
|
||||||
|
"recursion_limit" => {
|
||||||
|
if let Value::Int { val, internal_span } = value {
|
||||||
|
if val > &mut 1 {
|
||||||
|
config.recursion_limit = *val;
|
||||||
|
} else {
|
||||||
|
report_invalid_value("should be a integer greater than 1", span, &mut errors);
|
||||||
|
*value = Value::Int { val: 50, internal_span: *internal_span };
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
report_invalid_value("should be a integer greater than 1", span, &mut errors);
|
||||||
|
*value = Value::Int { val: 50, internal_span: value.span() };
|
||||||
|
}
|
||||||
|
}
|
||||||
// Catch all
|
// Catch all
|
||||||
_ => {
|
_ => {
|
||||||
report_invalid_key(&[key], span, &mut errors);
|
report_invalid_key(&[key], span, &mut errors);
|
||||||
|
@ -238,6 +238,7 @@ $env.config = {
|
|||||||
render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt.
|
render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt.
|
||||||
use_kitty_protocol: false # enables keyboard enhancement protocol implemented by kitty console, only if your terminal support this.
|
use_kitty_protocol: false # enables keyboard enhancement protocol implemented by kitty console, only if your terminal support this.
|
||||||
highlight_resolved_externals: false # true enables highlighting of external commands in the repl resolved by which.
|
highlight_resolved_externals: false # true enables highlighting of external commands in the repl resolved by which.
|
||||||
|
recursion_limit: 50 # the maximum number of times nushell allows recursion before stopping it
|
||||||
|
|
||||||
plugins: {} # Per-plugin configuration. See https://www.nushell.sh/contributor-book/plugins.html#configuration.
|
plugins: {} # Per-plugin configuration. See https://www.nushell.sh/contributor-book/plugins.html#configuration.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user