Complete error handling documentation for r2put.
All errors result in:
1Error Message:
ERROR: Missing required argument: --file
Run with --help for usage information.Causes:
--file argument not provided--bucket argument not providedResolution:
--help for usage informationError Message:
ERROR: File not found: /path/to/nonexistent.bin
Run with --help for usage information.Causes:
Resolution:
Error Message:
ERROR: Not a file: /path/to/directory
Run with --help for usage information.Causes:
Resolution:
Error Message:
ERROR: Missing CLOUDFLARE_ACCOUNT_ID environment variable
Run with --help for usage information.Causes:
Resolution:
CLOUDFLARE_ACCOUNT_IDR2_ACCESS_KEY_IDR2_SECRET_ACCESS_KEYexport)Error Display:
Common Causes:
Resolution:
Error Display:
Causes:
Resolution:
Error Display:
Causes:
Resolution:
0 - Upload completed successfully1 - Any error occurredSymptoms:
Resolution:
CLOUDFLARE_ACCOUNT_ID, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEYSymptoms:
Resolution:
Symptoms:
Resolution:
Symptoms:
Resolution:
Symptoms:
Resolution:
Before running r2put, verify:
File exists and is readable:
test -f ./data.bin && echo "File exists"Environment variables are set:
[ -n "$CLOUDFLARE_ACCOUNT_ID" ] && [ -n "$R2_ACCESS_KEY_ID" ] && [ -n "$R2_SECRET_ACCESS_KEY" ] && echo "All variables set"Bucket name is correct:
Network connectivity:
Example script with error handling:
#!/bin/bash
set -e
# Verify file exists
if [ ! -f "./data.bin" ]; then
echo "Error: File not found"
exit 1
fi
# Verify environment variables
if [ -z "$CLOUDFLARE_ACCOUNT_ID" ] || [ -z "$R2_ACCESS_KEY_ID" ] || [ -z "$R2_SECRET_ACCESS_KEY" ]; then
echo "Error: Missing required environment variables"
exit 1
fi
# Attempt upload
r2put --file ./data.bin --bucket my-bucket
# Check result
if [ $? -eq 0 ]; then
echo "Upload successful"
else
echo "Upload failed"
exit 1
fi