Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

musl+gcompat error #57

Open
Conaclos opened this issue Apr 5, 2023 · 6 comments
Open

musl+gcompat error #57

Conaclos opened this issue Apr 5, 2023 · 6 comments

Comments

@Conaclos
Copy link

Conaclos commented Apr 5, 2023

Hi! I tried to use a rust crate that relies on pico-args using Alpine Linux (Musl-based distrib) and gcompat (glibc compatibility layer). I got the following error:

Message: removal index (is 0) should be < len (is 0)

at the following line: https://github.com/RazrFalcon/pico-args/blob/master/src/lib.rs#L127

It could be nice to add a defensive check and then removing the path only if it is present.

@RazrFalcon
Copy link
Owner

RazrFalcon commented Apr 6, 2023

How is it possible not to have the executable path? Isn't this against the standard?

The first element is traditionally the path of the executable, but it can be set to arbitrary text, and might not even exist.

Damn...

@rjsberry
Copy link

rjsberry commented Apr 18, 2024

I've reproduced this on an M1 Mac:

$ docker run --rm -it --platform linux/amd64 alpine
# apk add gcompat libgcc

std::env::args_os() always returns an empty iterator, even if I pass the program arguments. For reference in this environment clap doesn't panic but of course it also doesn't work.

rust-lang/rust#124126

@rjsberry
Copy link

@Conaclos Looks like this will be working in Rust 1.79: rust-lang/rust#124447.

@RazrFalcon
Copy link
Owner

Nice! Even better then fixing it locally.

@duckinator
Copy link

I ran into this problem, but in a different context: I have a project that uses the same codebase for both native and wasm builds. I get this error on the wasm build.

At the moment I'm handling it in my app, but it feels like the wrong place to handle it.

In theory, I think adding a conditional to from_env() like this should fix it:

    pub fn from_env() -> Self {
        let mut args: Vec<_> = std::env::args_os().collect();
        if args.len() > 0 {
            args.remove(0);
        }
        Arguments(args)
    }

Would a PR adding that conditional be accepted, @RazrFalcon? Or should I just stick to the workaround in my project?

(Either way, thank you for making pico-args!)

@RazrFalcon
Copy link
Owner

like this should fix it

The problem is that I have to know if the first argument an exe path or not and I don't. You logic will not work for the most basic cases like -h. It would just eat the first argument.

The only solution I can think of is adding from_env_no_exe.

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

No branches or pull requests

4 participants