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:
pwygab
2024-03-29 04:40:45 +08:00
committed by GitHub
parent 8e763a2fd6
commit 04531357b4
3 changed files with 19 additions and 3 deletions

View File

@ -47,12 +47,12 @@ pub fn eval_call<D: DebugContext>(
// To prevent a stack overflow in user code from crashing the shell,
// we limit the recursion depth of function calls.
// 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;
if callee_stack.recursion_count > MAXIMUM_CALL_STACK_DEPTH {
if callee_stack.recursion_count > maximum_call_stack_depth {
callee_stack.recursion_count = 0;
return Err(ShellError::RecursionLimitReached {
recursion_limit: MAXIMUM_CALL_STACK_DEPTH,
recursion_limit: maximum_call_stack_depth,
span: block.span,
});
}