Skip to content

non-strings are not piped to external commands #14452

Open

Description

@ineu

Describe the bug

If a function returns value other than string, it is silently ignored when fed to an external command via pipe. This is unexpected.

How to reproduce

/home/ineu ▶ '123' | cat
123
/home/ineu ▶ 123 | cat
/home/ineu ▶ 123 | into string | cat
123

Expected behavior

If a function returns a value that is not a string (like int, float, bool etc) it should be implicitly converted into string when fed to an external command

Configuration

key value
version 0.100.0
major 0
minor 100
patch 0
branch makepkg
commit_hash 30f98f7
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.82.0 (f6e511eec 2024-10-15) (Arch Linux rust 1:1.82.0-2)
cargo_version cargo 1.82.0 (8f40fc59f 2024-08-21)
build_time 2024-11-13 08:00:49 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash
installed_plugins example 0.99.0, formats 0.99.1

Activity

  1. added
    status:needs-triage
    on Nov 27, 2024
  2. fdncred commented on Nov 27, 2024

    @fdncred
    Contributor

    why? what's the use case for this?

  3. added
    A:error-silent-fail
    on Nov 27, 2024
  4. sholderbach commented on Nov 27, 2024

    @sholderbach
    Member

    I don't think we should implicitly coerce but it should raise a mismatch if its not string or binary data going to an external.

  5. added
    A:external-commands
    A:redirection-pipe
    A:type-system
    and removed
    status:needs-triage
    on Nov 27, 2024
  6. ineu commented on Nov 28, 2024

    @ineu
    ContributorAuthor

    why? what's the use case for this?

    I originally faced this bug while creating a script to manage screen brightness. The logic to increase the brightness is:

    1. Read current and max absolute (device-specific) values from /sys
    2. Calculate the new value (which obviously emits an integer)
    3. Write the new value back to /sys

    So my code was:

    # Increase backlight
    def "main up" [percent = 10] {
        let new = [((absolute_current | absolute_to_percent) + $percent), 100] | math min
    
        $new | percent_to_absolute | sudo tee $current_file
    }

    and it took me some time to realize why sudo tee creates an empty file.

    I don't think we should implicitly coerce but it should raise a mismatch if its not string or binary data going to an external.

    That's a great option. Much better than silently ignoring the output.

  7. IanManske commented on Nov 28, 2024

    @IanManske
    Member

    We already implicitly convert for arguments to external commands, so I don't see why we can't for the piped input as well. As long as the conversion is consistent and documented, I think that would be a little more ergonomic (e.g., #14090).

    Alternatively, we could remove the implicit conversion for arguments if we want stricter typing. Either way, the two should match.

  8. 132ikl commented on Feb 28, 2025

    @132ikl
    Member

    Related: #14452

  9. 132ikl commented on Feb 28, 2025

    @132ikl
    Member

    I'm thinking we should explicitly list pipeline input types for run-external (unfortunately, this will be a shell error instead of a parse error until we fix the conditionally discarded pipeline input problem) only convert primitives with an obvious conversion.

    I agree with @IanManske on the point of argument conversions matching pipeline input conversions. I think we should only convert primitives which have an obvious conversion, but not things like dates, lists, records, etc. I think a decent heuristic is that the string representation is the same as the literal typed into the REPL then we implicitly convert, otherwise we don't.

    I might take a crack at this soon if I get the chance.

  10. kronberger-droid commented on Nov 14, 2026

    @kronberger-droid
    Contributor

    Still reproduces on 0.117: 123 | ^cat prints nothing.
    #16916 is the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-silent-failA:external-commandsA:redirection-pipeA:type-system

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions