envswitch 0.1.1

A tool for managing and switching environment variable configurations
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# EnvSwitch Error Messages Reference

This document provides a comprehensive reference for all error messages in EnvSwitch, their causes, and solutions.

## Table of Contents

- [Configuration Errors]#configuration-errors
- [Import/Export Errors]#importexport-errors
- [File System Errors]#file-system-errors
- [Validation Errors]#validation-errors
- [Shell Integration Errors]#shell-integration-errors
- [Interactive Editor Errors]#interactive-editor-errors
- [System Errors]#system-errors

## Configuration Errors

### `Configuration 'name' not found`

**Cause:** The specified configuration doesn't exist.

**Solutions:**
```bash
# List available configurations
envswitch list

# Check for similar names (EnvSwitch may suggest alternatives)
envswitch use myconfg  # May suggest "myconfig"

# Create the configuration
envswitch set name -e KEY=value
```

### `Configuration 'name' already exists`

**Cause:** Trying to create a configuration that already exists without using update mode.

**Solutions:**
```bash
# Update existing configuration
envswitch set name -e NEW_KEY=value  # Merges with existing

# Replace entire configuration
envswitch set name -e KEY=value --replace

# Delete and recreate
envswitch delete name --force
envswitch set name -e KEY=value
```

### `Cannot delete active configuration 'name'`

**Cause:** Trying to delete the currently active configuration.

**Solutions:**
```bash
# Switch to different configuration first
envswitch use other-config

# Or clear active configuration
envswitch clear

# Then delete
envswitch delete name
```

### `Configuration name contains invalid characters`

**Cause:** Configuration name contains spaces, special characters, or other invalid characters.

**Valid characters:** Letters (a-z, A-Z), numbers (0-9), hyphens (-), underscores (_)

**Solutions:**
```bash
# ✅ Valid names
envswitch set my-config -e KEY=value
envswitch set my_config -e KEY=value
envswitch set config123 -e KEY=value

# ❌ Invalid names - fix these
envswitch set "my config"     # Remove spaces: my-config
envswitch set "my.config"     # Replace dots: my-config
envswitch set "my@config"     # Remove special chars: myconfig
```

### `Configuration description too long`

**Cause:** Configuration description exceeds maximum length (usually 500 characters).

**Solutions:**
```bash
# Shorten the description
envswitch set config -e KEY=value -d "Shorter description"

# Or omit description
envswitch set config -e KEY=value
```

## Import/Export Errors

### `Import file 'filename' not found`

**Cause:** The specified import file doesn't exist or path is incorrect.

**Solutions:**
```bash
# Check file exists
ls -la filename.json

# Use absolute path
envswitch import /full/path/to/filename.json

# Check current directory
pwd
ls -la *.json
```

### `Invalid JSON format in import file`

**Cause:** The import file contains malformed JSON.

**Solutions:**
```bash
# Validate JSON syntax
python -m json.tool filename.json

# Fix JSON formatting
python -m json.tool filename.json > fixed.json
envswitch import fixed.json

# Check file encoding
file filename.json
```

### `Unsupported file format 'format'`

**Cause:** Trying to export/import in an unsupported format.

**Supported formats:** json, env, yaml

**Solutions:**
```bash
# Use supported format
envswitch export --format json -o configs.json
envswitch export --format env -o configs.env
envswitch export --format yaml -o configs.yaml

# Let EnvSwitch auto-detect from extension
envswitch export -o configs.json  # Auto-detects JSON
envswitch import configs.env       # Auto-detects ENV
```

### `Export directory not writable`

**Cause:** Don't have write permissions to the output directory.

**Solutions:**
```bash
# Check directory permissions
ls -la $(dirname output-file.json)

# Create directory if needed
mkdir -p $(dirname output-file.json)

# Fix permissions
chmod 755 $(dirname output-file.json)

# Export to writable location
envswitch export -o ~/configs.json
```

### `Import validation failed: invalid configuration structure`

**Cause:** Import file doesn't match expected EnvSwitch configuration format.

**Solutions:**
```bash
# Check file structure with dry-run
envswitch import filename.json --dry-run --verbose

# Skip validation if file is trusted
envswitch import filename.json --skip-validation

# Convert from other format
# If it's an ENV file:
envswitch import filename.env  # Auto-detects format
```

### `Configuration conflicts detected during import`

**Cause:** Import file contains configurations that already exist.

**Solutions:**
```bash
# Preview conflicts
envswitch import filename.json --dry-run

# Merge with existing configurations
envswitch import filename.json --merge --backup

# Overwrite existing configurations
envswitch import filename.json --force --backup

# Resolve manually
envswitch delete conflicting-config --force
envswitch import filename.json
```

### `Backup creation failed`

**Cause:** Cannot create backup file before import.

**Solutions:**
```bash
# Check backup directory permissions
ls -la ~/.config/envswitch/backups/

# Create backup directory
mkdir -p ~/.config/envswitch/backups/

# Fix permissions
chmod 755 ~/.config/envswitch/backups/

# Import without backup
envswitch import filename.json  # Without --backup flag
```

## File System Errors

### `Permission denied accessing configuration file`

**Cause:** Insufficient permissions to read/write configuration files.

**Solutions:**
```bash
# Fix file permissions
chmod 600 ~/.config/envswitch/config.json

# Fix directory permissions
chmod 700 ~/.config/envswitch/

# Fix ownership
chown -R $USER:$USER ~/.config/envswitch/
```

### `Configuration directory not found`

**Cause:** EnvSwitch configuration directory doesn't exist.

**Solutions:**
```bash
# Create configuration directory
mkdir -p ~/.config/envswitch/

# Set proper permissions
chmod 700 ~/.config/envswitch/

# Initialize with empty configuration
envswitch list  # Creates initial config file
```

### `Disk space insufficient`

**Cause:** Not enough disk space for operation.

**Solutions:**
```bash
# Check disk space
df -h ~/.config/

# Clean up old backups
find ~/.config/envswitch/backups -name "*.json" -mtime +30 -delete

# Move to location with more space
mv ~/.config/envswitch ~/Documents/envswitch-backup
ln -s ~/Documents/envswitch-backup ~/.config/envswitch
```

### `Configuration file is corrupted`

**Cause:** Configuration file contains invalid data or is corrupted.

**Solutions:**
```bash
# Restore from backup
ls ~/.config/envswitch/backups/
envswitch import ~/.config/envswitch/backups/latest.json --force

# Start with fresh configuration
mv ~/.config/envswitch/config.json ~/.config/envswitch/config.json.corrupted
envswitch list  # Creates new empty config

# Manual repair (advanced)
python -m json.tool ~/.config/envswitch/config.json
```

## Validation Errors

### `Invalid environment variable name 'name'`

**Cause:** Environment variable name contains invalid characters.

**Valid format:** Letters, numbers, underscores only. Must start with letter or underscore.

**Solutions:**
```bash
# ✅ Valid variable names
envswitch set config -e VALID_NAME=value
envswitch set config -e _PRIVATE_VAR=value
envswitch set config -e VAR123=value

# ❌ Invalid names - fix these
envswitch set config -e "invalid-name=value"  # Use: INVALID_NAME
envswitch set config -e "123invalid=value"    # Use: VAR_123_INVALID
envswitch set config -e "var.name=value"      # Use: VAR_NAME
```

### `Environment variable value too long`

**Cause:** Environment variable value exceeds maximum length.

**Solutions:**
```bash
# Shorten the value
envswitch set config -e LONG_VAR="shorter value"

# Use file reference instead
echo "very long value" > /tmp/longvalue.txt
envswitch set config -e LONG_VAR="$(cat /tmp/longvalue.txt)"

# Split into multiple variables
envswitch set config -e PART1="first part" -e PART2="second part"
```

### `Too many environment variables in configuration`

**Cause:** Configuration exceeds maximum number of variables (usually 1000).

**Solutions:**
```bash
# Split into multiple configurations
envswitch set config-part1 -e VAR1=value1 -e VAR2=value2
envswitch set config-part2 -e VAR3=value3 -e VAR4=value4

# Remove unused variables
envswitch edit config  # Use interactive editor to remove variables
```

### `Duplicate environment variable 'name'`

**Cause:** Same variable name specified multiple times.

**Solutions:**
```bash
# Remove duplicate from command
envswitch set config -e VAR=value1  # Don't repeat -e VAR=value2

# Use replace mode to overwrite
envswitch set config -e VAR=new_value --replace
```

## Shell Integration Errors

### `Shell detection failed`

**Cause:** Cannot determine current shell type.

**Solutions:**
```bash
# Check current shell
echo $SHELL

# Set SHELL environment variable
export SHELL=/bin/zsh  # or /bin/bash, /usr/local/bin/fish

# Force shell type
envswitch use config --shell zsh
```

### `Unsupported shell 'shell_name'`

**Cause:** Shell type is not supported by EnvSwitch.

**Supported shells:** bash, zsh, fish, sh

**Solutions:**
```bash
# Use supported shell
export SHELL=/bin/bash
envswitch use config

# Generate commands manually
envswitch use config --dry-run > temp_vars.sh
source temp_vars.sh  # For bash/zsh
```

### `Shell command generation failed`

**Cause:** Error generating shell-specific commands.

**Solutions:**
```bash
# Use dry-run to see generated commands
envswitch use config --dry-run

# Try different shell
SHELL=/bin/bash envswitch use config

# Manual variable setting
envswitch show config  # Copy variables manually
export VAR1=value1
export VAR2=value2
```

## Interactive Editor Errors

### `Interactive editor initialization failed`

**Cause:** Cannot start interactive editor.

**Solutions:**
```bash
# Check terminal capabilities
echo $TERM

# Use non-interactive mode
envswitch set config -e KEY=value

# Try different terminal
# Run in different terminal emulator
```

### `Input validation failed in editor`

**Cause:** Invalid input provided in interactive editor.

**Solutions:**
```bash
# Follow the prompts carefully
# Variable names: Use only letters, numbers, underscores
# Values: Avoid special characters that might cause issues

# Exit and use command line
# Press 'q' to quit editor
envswitch set config -e VALID_NAME=value
```

### `Editor session corrupted`

**Cause:** Interactive editor session became corrupted.

**Solutions:**
```bash
# Exit editor (press 'q')
# Try again
envswitch edit config

# Use command line instead
envswitch set config -e KEY=value

# Check terminal settings
stty sane
```

## System Errors

### `Command execution timeout`

**Cause:** Operation took too long to complete.

**Solutions:**
```bash
# Use specific operations instead of bulk operations
envswitch export -c "config1,config2" -o subset.json

# Check system resources
top
df -h

# Restart and try again
```

### `Memory allocation failed`

**Cause:** Insufficient memory for operation.

**Solutions:**
```bash
# Close other applications
# Check memory usage
free -h

# Use smaller operations
envswitch export -c "single-config" -o small.json

# Restart system if needed
```

### `Network connection failed`

**Cause:** Network-related operation failed (if applicable).

**Note:** EnvSwitch is primarily local, but some operations might require network access.

**Solutions:**
```bash
# Check network connectivity
ping google.com

# Use offline mode if available
# Retry operation

# Check firewall settings
```

## Error Code Reference

EnvSwitch uses standard exit codes:

- `0`: Success
- `1`: General error
- `2`: Misuse of shell command
- `64`: Command line usage error
- `65`: Data format error
- `66`: Cannot open input
- `67`: Addressee unknown
- `68`: Host name unknown
- `69`: Service unavailable
- `70`: Internal software error
- `71`: System error
- `72`: Critical OS file missing
- `73`: Can't create output file
- `74`: Input/output error
- `75`: Temporary failure
- `76`: Remote error in protocol
- `77`: Permission denied
- `78`: Configuration error

## Getting Detailed Error Information

### Verbose Mode

Always use verbose mode when troubleshooting:

```bash
envswitch command --verbose
```

### Error Context

Most errors include context information:
- What operation was being performed
- What file or configuration was involved
- Suggestions for resolution

### Debug Information

For complex issues, gather debug information:

```bash
# System information
uname -a
echo $SHELL

# EnvSwitch version
envswitch --version

# Configuration status
envswitch list --verbose

# File permissions
ls -la ~/.config/envswitch/

# Disk space
df -h ~/.config/
```

## Reporting Bugs

When reporting errors, include:

1. **Error message** (exact text)
2. **Command used** (full command line)
3. **System information** (OS, shell, EnvSwitch version)
4. **Steps to reproduce**
5. **Expected vs actual behavior**
6. **Verbose output** (if applicable)

Example bug report:
```
Error: Configuration 'test' not found

Command: envswitch use test --verbose

System: macOS 12.6, zsh 5.8.1, EnvSwitch 0.1.0

Steps:
1. envswitch set test -e KEY=value
2. envswitch list (shows 'test' configuration)
3. envswitch use test (fails with error)

Expected: Should switch to 'test' configuration
Actual: Error message about configuration not found

Verbose output:
[verbose output here]
```