macOS Error -108 (nameErr) — Invalid Name
Error -108 (nameErr) means the system received a name that is invalid or cannot be used. On macOS, this applies to filenames, directory names, volume names, hostnames, and AppleScript object names. The error appears when trying to create, rename, or access resources with names containing restricted characters, invalid encoding, or names that conflict with system conventions.
Common Causes
- Filename contains colon (:) or slash (/) characters
- Name exceeds the maximum allowed length (255 bytes on APFS)
- Invalid UTF-8 encoding in the filename
- Name contains only whitespace or special characters
- Reserved names like “com1”, “nul”, or “prn” (from Windows)
- Name conflicts with existing items in the same directory
- Null bytes (\0) embedded in the name
How to Fix Error -108
1. Inspect the Problematic Name
Check the filename for invalid characters:
# Show non-printable characters in filenames
ls -la | cat -v
# Find files with unusual characters
find . -maxdepth 1 -print0 | xargs -0 -I {} bash -c '
if echo "$1" | grep -qP "[^\\x20-\\x7E]"; then
echo "Problematic: $1"
fi
' _ {}
# Show the exact bytes in a filename
ls -la | od -c | head -20
2. Remove Invalid Characters
macOS filenames cannot contain these characters:
:(colon) — used as path separator internally/(forward slash) — path separator\0(null byte)
# Find files with colons in the name
find . -maxdepth 1 -name '*:*' -print
# Rename a file to remove invalid characters
mv "./file:name.txt" "./filename.txt"
# Handle files with unusual names using their inode
ls -i problem_file
find . -inum <inode_number> -exec mv {} new_name \;
3. Fix UTF-8 Encoding Issues
Ensure filenames are valid UTF-8:
# Check if a filename is valid UTF-8
python3 -c "
import os
for name in os.listdir('.'):
try:
name.encode('utf-8').decode('utf-8')
except UnicodeDecodeError:
print(f'Invalid UTF-8: {name!r}')
"
# Convert a filename from latin-1 to UTF-8
python3 -c "
import os, unicodedata
for name in os.listdir('.'):
try:
fixed = name.encode('latin-1').decode('utf-8')
if fixed != name:
os.rename(name, fixed)
print(f'Renamed: {name!r} -> {fixed!r}')
except (UnicodeDecodeError, UnicodeEncodeError):
pass
"
4. Check Filename Length
APFS supports up to 255 characters, but the full path has limits:
# Check filename length
python3 -c "
import os
for name in os.listdir('.'):
if len(name) > 255:
print(f'Too long ({len(name)} chars): {name!r}')
"
# Check full path length
python3 -c "
import os
path = os.path.abspath('problem_file')
print(f'Path length: {len(path)} bytes')
if len(path.encode()) > 1024:
print('Path may be too long for some operations')
"
5. Rename Using Terminal
If Finder shows the error, use Terminal for more control:
# Use quotes for filenames with spaces or special chars
mv "file with spaces.txt" "newname.txt"
# Use backslash for specific special characters
mv file\:name.txt filename.txt
# Use quotes for names starting with a dash
mv -- "-filename.txt" "filename.txt"
# Use inode for completely broken names
ls -i
find . -inum <inode> -exec mv {} fixed_name.txt \;
6. Handle AppleScript Object Names
In AppleScript, nameErr occurs with invalid object names:
-- Wrong: name contains invalid character
tell application "Finder"
make new folder at desktop with properties {name:"Folder:Invalid"}
end tell
-- Right: use valid name
tell application "Finder"
make new folder at desktop with properties {name:"Folder Invalid"}
end tell
-- Handle nameErr in AppleScript
try
tell application "Finder"
set name of folder "Old Name" to "New Name"
end tell
on error number -108
display dialog "Invalid name. Please use a different name without colons or slashes."
end try
7. Fix Volume Names
Volume names have additional restrictions:
# Check current volume names
diskutil list
# Rename a volume
diskutil rename /Volumes/OldName "New Name"
# APFS volume names cannot contain:
# - Colons
# - Leading/trailing periods
# - The name "Volumes"
8. Fix Hostname Issues
A bad hostname can cause nameErr:
# Check current hostname
hostname
# Set a valid hostname
sudo scutil --set HostName "my-mac.local"
# Verify it is a valid DNS name
python3 -c "
import re
hostname = 'my-mac.local'
if re.match(r'^[a-zA-Z0-9._-]+$', hostname):
print('Valid hostname')
else:
print('Invalid hostname')
"
Related Error Codes
- macOS error -50 (paramErr) — Parameter Error
- macOS error -43 (fnfErr) — File Not Found
- Linux ENAMETOOLONG (errno 36) — File name too long
Comments