Repository: zellij-org/zellij (language: rust)

Issue:
Long session name hangs zellij
`zellij --session reallyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy` works. 
`zellij --session reallyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy` is hanging the program.

The latter one is 37 characters long


Discussion / hints:
Nice find!

This is the error in the logs:
```
ERROR  |zellij_utils::errors::not| 2023-07-04 16:03:50.078 [server_listener] [zellij-utils/src/errors.rs:601]: Panic occured:
             thread: server_listener
             location: At zellij-server/src/lib.rs:281:25
             message: socket path should not be longer than 108 bytes
```

The fix for this should be validating `session` on the `clap` level in `zellij_utils/src/cli.rs`.
I would like to contribute to this issue
Go for it :)
Hi! I was trying to reproduce the issue and the maximum length of session name that worked for me (no hang) was  78 characters. (need help here)
And the way I intended to validate the session is by defining  the function:

```rust
fn  validate_session_length(name: &str) -> Result<String,String> {
    if name.len() > 78 {  // or whatever length that works
        Err(format!("Session name must be less than 78 bytes"))
    } else {
        return Ok(name.to_owned())
    }
}
```

at `zellij_utils/src/cli.rs` and using this function as value_parser for `session` of the `CliArgs` struct. 

Do you know if this is the correct way to do this? Did I miss anything? Sorry for asking too many questions. 
@deepsghimire - what I can say is that we want the user to get a proper error in the CLI, with coloring, the correct exit status and everything. The rest is up to you as the implementer.

I think the session name limit is platform specific (for me the number was 108) - so do look into that, we might need to be a little smarter about this.

Thanks for looking into this!
In my case, the issue presents itself when the session length is at least 38 characters

> Nice find!
> 
> This is the error in the logs:
> 
> ```
> ERROR  |zellij_utils::errors::not| 2023-07-04 16:03:50.078 [server_listener] [zellij-utils/src/errors.rs:601]: Panic occured:
>              thread: server_listener
>              location: At zellij-server/src/lib.rs:281:25
>              message: socket path should not be longer than 108 bytes
> ```
> 
> The fix for this should be validating `session` on the `clap` level in `zellij_utils/src/cli.rs`.

It looks like this error is outdated as master has a comment on the line the error quotes.

How can I get zellij to produce similar logs for me? I do not get this even when running zellij with the `--debug` flag.
@super-secret-github-user I used `cargo xtask run`

Fix patch:
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs
index 6639f810b6..5377889a2d 100644
--- a/zellij-utils/src/cli.rs
+++ b/zellij-utils/src/cli.rs
@@ -9,6 +9,30 @@ use serde::{Deserialize, Serialize};
 use std::path::PathBuf;
 use url::Url;
 
+fn validate_session(name: &str) -> Result<String, String> {
+    #[cfg(unix)]
+    {
+        use crate::consts::ZELLIJ_SOCK_MAX_LENGTH;
+
+        let mut socket_path = crate::consts::ZELLIJ_SOCK_DIR.clone();
+        socket_path.push(name);
+
+        if socket_path.as_os_str().len() >= ZELLIJ_SOCK_MAX_LENGTH {
+            // socket path must be less than 108 bytes
+            let available_length = ZELLIJ_SOCK_MAX_LENGTH
+                .saturating_sub(socket_path.as_os_str().len())
+                .saturating_sub(1);
+
+            return Err(format!(
+                "session name must be less than {} characters",
+                available_length
+            ));
+        };
+    };
+
+    Ok(name.to_owned())
+}
+
 #[derive(Parser, Default, Debug, Clone, Serialize, Deserialize)]
 #[clap(version, name = "zellij")]
 pub struct CliArgs {
@@ -25,7 +49,7 @@ pub struct CliArgs {
     pub server: Option<PathBuf>,
 
     /// Specify name of a new session
-    #[clap(long, short, overrides_with = "session", value_parser)]
+    #[clap(long, short, overrides_with = "session", value_parser = validate_session)]
     pub session: Option<String>,
 
     /// Name of a predefined layout inside the layout directory or the path to a layout file
diff --git a/zellij-utils/src/consts.rs b/zellij-utils/src/consts.rs
index 50600a9342..f51698f809 100644
--- a/zellij-utils/src/consts.rs
+++ b/zellij-utils/src/consts.rs
@@ -107,6 +107,8 @@ mod unix_only {
     use nix::unistd::Uid;
     use std::{env::temp_dir, fs};
 
+    pub const ZELLIJ_SOCK_MAX_LENGTH: usize = 108;
+
     lazy_static! {
         static ref UID: Uid = Uid::current();
         pub static ref ZELLIJ_IPC_PIPE: PathBuf = {


Test patch: