Skip to content

Troubleshooting

Error: Failed to bind to address: Address already in use (os error 98)

Cause: The specified port (default 3000) is already in use

Solutions:

  • Use a different port
Terminal window
mocks run -p 8080 storage.json
  • Kill the existing process
Terminal window
# Find process using port 3000
lsof -i :3000
# Kill the process
kill -9 <PID>

Issue: “No such file or directory” Error

Section titled “Issue: “No such file or directory” Error”
Error: No such file or directory (os error 2)

Cause: The specified JSON file doesn’t exist

Solutions:

  • Verify the file path
  • Check if the file exists
Terminal window
ls -la storage.json
Error: Invalid JSON in storage file

Cause: JSON file has syntax errors

Solutions:

  • Validate JSON syntax
  • Use an online JSON validator
  • Check for common errors:
    • Missing commas
    • Unmatched brackets
    • Incorrect quotation marks

Issue: “Duplicate resource names” Error

Section titled “Issue: “Duplicate resource names” Error”
Error: Duplicate resource names found

Cause: JSON file contains duplicate resource names

Solutions:

  • Make resource names unique
  • Example: Cannot have both api/v1/users and api/v2/users

Causes:

  • Accessing non-existent endpoints
  • Using non-existent resource IDs

Solutions:

  • Verify endpoint paths
  • Check if resource IDs are correct
  • Review available endpoints

Causes:

  • Sending invalid JSON data
  • Using incorrect search query format

Solutions:

  • Validate request body JSON
  • Check search query format (must be field.matchtype=value)

Causes:

  • Incorrect search query format
  • Trying to search on single object resources

Solutions:

  • Use correct search format: field.matchtype=value
  • Only use search on array-type resources
  • Use supported match types (exact, contains, startswith, endswith)

Correct example:

Terminal window
curl "http://localhost:3000/posts?title.contains=post"

Incorrect example:

Terminal window
curl "http://localhost:3000/posts?title=post" # Missing match type

Causes:

  • --no-overwrite option is specified
  • No file write permissions

Solutions:

  • Remove --no-overwrite option
  • Check file write permissions
Terminal window
ls -la storage.json
chmod 644 storage.json

Causes:

  • Unexpected program termination
  • Invalid data writes

Solutions:

  • Use debug mode to create backups
Terminal window
MOCKS_DEBUG_OVERWRITTEN_FILE=storage.debug.json mocks run storage.json
  • Regularly backup JSON files
Terminal window
cp storage.json storage.backup.json

Causes:

  • Large JSON files
  • Complex search queries

Solutions:

  • Reduce JSON file size
  • Remove unnecessary data
  • Use more specific search conditions

Cause: Cross-Origin Resource Sharing (CORS) restrictions

Solutions:

  • For development, disable browser CORS restrictions
  • Use a proxy server
  • Configure reverse proxy with nginx or Apache

mocks outputs logs to stdout:

Terminal window
mocks run storage.json
Terminal window
MOCKS_DEBUG_OVERWRITTEN_FILE=storage.debug.json mocks run storage.json
Terminal window
RUST_LOG=debug mocks run storage.json

Verify server is running:

Terminal window
curl -i http://localhost:3000/_hc
  1. Backup JSON Files

    • Regularly backup important data
  2. Version Control

    • Keep JSON files in Git
    • Add *.debug.json to .gitignore
  3. Separate Test Data

    • Keep production and test data separate
    • Use appropriate file naming (e.g., storage.test.json)
  4. Resource Design

    • Use unique resource names
    • Design proper ID structures

If issues persist, you can seek help through:

  • GitHub Issues: mocks-rs/mocks
  • Version Check: mocks --version
  • System Info: OS, Rust version (if applicable)

When reporting issues, please include:

  • mocks version
  • Operating system
  • Error messages
  • JSON file (if possible)
  • Commands executed

Save modified data to a separate file:

Terminal window
MOCKS_DEBUG_OVERWRITTEN_FILE=storage.debug.json mocks run storage.json

Enable debug logging:

Terminal window
RUST_LOG=debug mocks run storage.json
Terminal window
# Wrong: Will only bind to localhost
mocks run storage.json
# Right: For Docker or external access
mocks run -H 0.0.0.0 storage.json
Terminal window
# Wrong: Relative path might not work
mocks run ../data/storage.json
# Right: Use absolute path or correct relative path
mocks run /full/path/to/storage.json
{
"users": [
{ "id": "1", "name": "John" }
],
"profile": { "id": "1", "name": "App" }
}
{
"users": [
{ "name": "John" } // Missing required ID
],
"api/v1/users": [ // Duplicate resource name
{ "id": "1", "name": "Jane" }
]
}

Remember that proper JSON structure and unique resource names are essential for mocks to work correctly.