# Troubleshooting

Common issues and solutions for SRX.

---

## Installation Issues

### Rust Not Found

**Error:**
```
error: rustc: command not found
```

**Solution:**
Install Rust using rustup:
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
```

### Build Fails - Missing Dependencies

**Error:**
```
error: linking with `cc` failed
```

**Solution:**
Install a C compiler:

**Ubuntu/Debian:**
```bash
sudo apt install build-essential
```

**Fedora/RHEL:**
```bash
sudo dnf install gcc
```

**macOS:**
```bash
xcode-select --install
```

### Build Fails - Out of Memory

**Error:**
```
error: the linker exited unexpectedly
```

**Solution:**
Reduce parallelism during build:
```bash
CARGO_BUILD_JOBS=2 cargo build --release
```

---

## Password Issues

### Invalid Password Error

**Error:**
```
Error: Invalid password
```

**Possible Causes:**

1. **Wrong Password**
   - Verify the password is correct
   - Check for typos

2. **Keyboard Layout**
   - Ensure correct keyboard layout
   - Check for special characters

3. **Copy-Paste Issues**
   - Hidden characters may be included
   - Try typing the password manually

4. **Caps Lock**
   - Check if Caps Lock is enabled

**Debug Steps:**
```bash
# Test password in a text editor first
echo "your_password" | cat

# Use interactive password input
srx unpack archive.srx
# You'll be prompted for password
```

### Password Not Accepted During Pack

**Error:**
```
Error: Password too short
```

**Solution:**
Use a longer password (minimum 8 characters recommended).

---

## Archive Issues

### Corrupted Archive

**Error:**
```
Error: Corrupted archive
```

**Possible Causes:**

1. **Incomplete Transfer**
   - File was not fully downloaded/copied
   - Verify file size matches expected

2. **Disk Corruption**
   - Run `fsck` on Linux
   - Check disk health

3. **Tampering**
   - File was modified
   - Authentication tag mismatch

**Debug Steps:**
```bash
# Check file size
ls -la archive.srx

# Check file type
file archive.srx

# Try to read header
xxd archive.srx | head -5
# Should start with: 5352 5831 (SRX1)
```

### Invalid Format

**Error:**
```
Error: Invalid format
```

**Possible Causes:**

1. **Not an SRX File**
   - File is not an SRX archive
   - Check file extension and content

2. **Wrong Version**
   - Archive created with newer SRX version
   - Update SRX

**Debug Steps:**
```bash
# Check magic bytes
xxd archive.srx | head -1
# Should show: 5352 5831 (SRX1)

# Check SRX version
srx --version
```

### Archive Too Large After Packing

**Issue:**
Archive is larger than original file.

**Possible Causes:**

1. **Pre-compressed Data**
   - Videos, images, zip files are already compressed
   - Use `-a none` to skip compression

2. **Random Data**
   - Encrypted or random data cannot be compressed

3. **Small Files**
   - Metadata overhead for small files

**Solution:**
```bash
# For pre-compressed files
srx pack video.mp4 video.srx -p "key" -a none

# For mixed content, use tar first
tar -cf data.tar files/
srx pack data.tar data.srx -p "key"
```

---

## Performance Issues

### Slow Compression

**Issue:**
Compression takes too long.

**Solutions:**

1. **Use Lower Compression Level**
   ```bash
   srx pack file.txt file.srx -p "key" -l 1
   ```

2. **Use LZ4 Algorithm**
   ```bash
   srx pack file.txt file.srx -p "key" -a lz4
   ```

3. **Check Disk I/O**
   ```bash
   iostat -x 1
   ```

4. **Use Release Build**
   ```bash
   cargo build --release
   ```

### Slow Decompression

**Issue:**
Extraction is slow.

**Solutions:**

1. **Check Compression Level**
   - High compression levels decompress slower
   - Use `srx info` to check compression settings

2. **Check Disk Write Speed**
   ```bash
   dd if=/dev/zero of=test bs=1M count=1000
   ```

3. **Check Available Memory**
   ```bash
   free -h
   ```

### High Memory Usage

**Issue:**
SRX uses too much memory.

**Solutions:**

1. **Reduce Argon2 Memory**
   ```bash
   export SRX_MEMORY_LIMIT=32
   srx pack file.txt file.srx -p "key"
   ```

2. **Use Smaller Chunks**
   ```bash
   srx pack file.txt file.srx -p "key" -c 65536
   ```

3. **Reduce Parallelism**
   ```bash
   export RAYON_NUM_THREADS=2
   srx pack file.txt file.srx -p "key"
   ```

---

## I/O Issues

### File Not Found

**Error:**
```
Error: No such file or directory
```

**Solutions:**

1. **Check File Path**
   ```bash
   ls -la /path/to/file
   ```

2. **Use Absolute Paths**
   ```bash
   srx pack /home/user/file.txt file.srx -p "key"
   ```

3. **Check Working Directory**
   ```bash
   pwd
   ```

### Permission Denied

**Error:**
```
Error: Permission denied
```

**Solutions:**

1. **Check File Permissions**
   ```bash
   ls -la file.txt
   ```

2. **Check Directory Permissions**
   ```bash
   ls -la /path/to/directory
   ```

3. **Run with Appropriate Permissions**
   ```bash
   # Read file you own
   srx pack file.txt file.srx -p "key"
   
   # Write to directory you own
   srx pack file.txt /home/user/file.srx -p "key"
   ```

### Disk Full

**Error:**
```
Error: No space left on device
```

**Solutions:**

1. **Check Disk Space**
   ```bash
   df -h
   ```

2. **Clean Up Space**
   ```bash
   # Remove old archives
   rm old_archive.srx
   
   # Clear cache
   rm -rf ~/.cache/srx
   ```

3. **Write to Different Location**
   ```bash
   srx pack file.txt /mnt/external/file.srx -p "key"
   ```

---

## Platform-Specific Issues

### Linux: Library Not Found

**Error:**
```
error while loading shared libraries: libgcc_s.so.1
```

**Solution:**
```bash
# Ubuntu/Debian
sudo apt install libgcc1

# Fedora/RHEL
sudo dnf install libgcc
```

### macOS: Cannot Open App

**Error:**
```
"srx" cannot be opened because the developer cannot be verified
```

**Solution:**
```bash
# Allow the app
xattr -cr srx

# Or in System Preferences > Security & Privacy > Open Anyway
```

### Windows: Access Denied

**Error:**
```
Error: Access is denied
```

**Solutions:**

1. **Run as Administrator**
   - Right-click Command Prompt
   - Select "Run as administrator"

2. **Check Antivirus**
   - Antivirus may block file operations
   - Add exception for SRX

3. **Check File Locks**
   - File may be open in another program
   - Close any programs using the file

---

## Debugging

### Enable Verbose Output

```bash
srx pack file.txt file.srx -p "key" -v
```

### Check SRX Version

```bash
srx --version
```

### Verify Archive Integrity

```bash
srx info archive.srx -p "password"
```

### Examine Archive Header

```bash
xxd archive.srx | head -20
```

### Check System Resources

```bash
# Memory
free -h

# CPU
lscpu

# Disk
df -h
iostat -x 1
```

---

## Getting Help

If you can't resolve an issue:

1. **Check Documentation**
   - [FAQ](FAQ)
   - [CLI Reference](CLI-Reference)
   - [Getting Started](Getting-Started)

2. **Search Existing Issues**
   - [GitHub Issues](https://github.com/Jamshed-develop/srx/issues)

3. **Open a New Issue**
   - Include SRX version: `srx --version`
   - Include OS and version
   - Include full error message
   - Include steps to reproduce

4. **Provide Debug Info**
   ```bash
   # System info
   uname -a
   srx --version
   
   # Verbose output
   srx pack file.txt file.srx -p "key" -v 2>&1 | tee debug.log
   ```

---

## See Also

- [FAQ](FAQ) - Frequently asked questions
- [CLI Reference](CLI-Reference) - Command options
- [Performance](Performance) - Optimization tips