Skip to content

Refactor env conversion to eliminate Value::follow_cell_path_not_from_user_input#10926

Merged
sholderbach merged 3 commits intonushell:mainfrom
IanManske:env-follow-record
Nov 8, 2023
Merged

Refactor env conversion to eliminate Value::follow_cell_path_not_from_user_input#10926
sholderbach merged 3 commits intonushell:mainfrom
IanManske:env-follow-record

Conversation

@IanManske
Copy link
Copy Markdown
Member

@IanManske IanManske commented Nov 2, 2023

Description

Replaces the only usage of Value::follow_cell_path_not_from_user_input with some Record::gets.

User-Facing Changes

Breaking change for nu-protocol, since Value::follow_cell_path_not_from_user_input was deleted.

Nushell now reports errors for when environment conversions are not closures.

Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me

Comment on lines +373 to +376
.and_then(|val| val.as_record().ok())
.and_then(|record| record.get(name))
.and_then(|val| val.as_record().ok())
.and_then(|record| record.get(direction));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust, you love to see it 😁

@IanManske
Copy link
Copy Markdown
Member Author

IanManske commented Nov 8, 2023

Hmm... I'm not sure why but I'm getting some jarbbled error output if the conversion is not a closure.

/home/iamaError: nu::shell::cant_convert

                                          × Can't convert to closure.
                                                                         ╭─[/home/iama/.config/nushell/env.nu:23:1]
                                                                                                                    23 │     from_string: "nope"
                                                                                                                                                 24 │     to_string: "nope"
                                                                                                                                                                               ·                ───┬──
                                                                                                                                                                                                          ·                   ╰── can't convert string to closure
          25 │   }
                      ╰────

/home/iama
Error: nu::shell::cant_convert

  × Can't convert to closure.
    ╭─[/home/iama/.config/nushell/env.nu:23:1]
 23 │     from_string: "nope"
 24 │     to_string: "nope"
    ·                ───┬──
    ·                   ╰── can't convert string to closure
 25 │   }
    ╰────

And it only happens on the fourth time I press enter (I think once the text reaches the bottom of the terminal).

Should we treat this as a separate issue?

@sholderbach
Copy link
Copy Markdown
Member

And it only happens on the fourth time I press enter (I think once the text reaches the bottom of the terminal).

Should we treat this as a separate issue?

Can you reproduce something similar on main?
I don't know what the exact error reporting mechanism is here but that is probably a problem somewhere else.

To me it looks like it is outputting while the terminal is still in raw mode so the carriage return is not automatically added for \n.

I think worth filing a separate issue.

sholderbach added a commit that referenced this pull request Nov 8, 2023
# Description

This is pretty complementary/orthogonal to @IanManske 's changes to
`Value` cellpath accessors in:
- #10925
- to a lesser extent #10926

## Steps
- Use `R.remove` in `Value.remove_data_at_cell_path`
- Pretty sound after #10875 (tests mentioned in commit message have been
removed by that)
- Update `did_you_mean` helper to use iterator
- Change `Value::columns` to return iterator
  - This is not a place of honor
- Use `Record::get` in `Value::get_data_by_key`
# User-Facing Changes
None intentional, potential edge cases on duplicated columns could
change (considered undefined behavior)

# Tests + Formatting
(-)
@IanManske
Copy link
Copy Markdown
Member Author

Ok, opened a separate issue. That one was a doozy to figure out.

@sholderbach
Copy link
Copy Markdown
Member

Let's go with this!

@sholderbach sholderbach merged commit aed4b62 into nushell:main Nov 8, 2023
@IanManske IanManske deleted the env-follow-record branch November 10, 2023 17:12
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
# Description

This is pretty complementary/orthogonal to @IanManske 's changes to
`Value` cellpath accessors in:
- nushell#10925
- to a lesser extent nushell#10926

## Steps
- Use `R.remove` in `Value.remove_data_at_cell_path`
- Pretty sound after nushell#10875 (tests mentioned in commit message have been
removed by that)
- Update `did_you_mean` helper to use iterator
- Change `Value::columns` to return iterator
  - This is not a place of honor
- Use `Record::get` in `Value::get_data_by_key`
# User-Facing Changes
None intentional, potential edge cases on duplicated columns could
change (considered undefined behavior)

# Tests + Formatting
(-)
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
…ll#10926)

# Description
Replaces the only usage of `Value::follow_cell_path_not_from_user_input`
with some `Record::get`s.

# User-Facing Changes
Breaking change for `nu-protocol`, since
`Value::follow_cell_path_not_from_user_input` was deleted.

Nushell now reports errors for when environment conversions are not
closures.
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description

This is pretty complementary/orthogonal to @IanManske 's changes to
`Value` cellpath accessors in:
- nushell#10925
- to a lesser extent nushell#10926

## Steps
- Use `R.remove` in `Value.remove_data_at_cell_path`
- Pretty sound after nushell#10875 (tests mentioned in commit message have been
removed by that)
- Update `did_you_mean` helper to use iterator
- Change `Value::columns` to return iterator
  - This is not a place of honor
- Use `Record::get` in `Value::get_data_by_key`
# User-Facing Changes
None intentional, potential edge cases on duplicated columns could
change (considered undefined behavior)

# Tests + Formatting
(-)
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
…ll#10926)

# Description
Replaces the only usage of `Value::follow_cell_path_not_from_user_input`
with some `Record::get`s.

# User-Facing Changes
Breaking change for `nu-protocol`, since
`Value::follow_cell_path_not_from_user_input` was deleted.

Nushell now reports errors for when environment conversions are not
closures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants