Troubleshooting Guide
This guide helps you diagnose and resolve common issues when using datagen commands.
Table of Contents
Section titled “Table of Contents”Transpilation Errors
Section titled “Transpilation Errors”Transpilation errors occur when datagen converts your .dg files to Go code.
1. “Model X should be in file named X.dg”
Section titled “1. “Model X should be in file named X.dg””Problem: Model name doesn’t match filename.
Solution: Rename file or change model name to match.
model users {  // ✓ Correct - matches filename  // ...}
// File: User.dgmodel User {   // ✓ Correct - matches filename  // ...}2. “Field X has no corresponding generation function”
Section titled “2. “Field X has no corresponding generation function””Problem: You defined a field but forgot to create its generation function.
Solution: Add the missing generation function.
fields {  name() string  age() int}
gens {  func name() {    return Name()  }  // Missing: func age() { ... }}3. “Generation function X has no corresponding field”
Section titled “3. “Generation function X has no corresponding field””Problem: You created a generation function but forgot to define the field.
Solution: Add the missing field definition.
fields {  name() string  // Missing: age() int}
gens {  func name() {    return Name()  }  func age() {  // No corresponding field    return IntBetween(18, 65)  }}4. “Parameterized field X requires calls section”
Section titled “4. “Parameterized field X requires calls section””Problem: You have a parameterized field but no calls section.
Solution: Add the calls section with arguments.
fields {  created_at(start time.Time, end time.Time) time.Time}
gens {  func created_at(start time.Time, end time.Time) {    return DateBetween(start, end)  }}
// Missing calls section - add this:calls {  created_at(time.Now().AddDate(-1, 0, 0), time.Now())}5. “Syntax error in model file”
Section titled “5. “Syntax error in model file””Problem: Invalid syntax in your .dg file.
Common issues:
- Missing braces 
{} - Incorrect field syntax
 - Invalid Go syntax in generation functions
 
Solution: Check your syntax carefully.
// Wrongfields {  name string  // Missing parentheses and type}
// Correctfields {  name() string}Generation Errors
Section titled “Generation Errors”Generation errors occur when running datagen gen command.
1. “No .dg files found”
Section titled “1. “No .dg files found””Problem: No model files found in the specified directory.
Solutions:
# Check current directorypwd
# List .dg filesls -la *.dg
# Use correct pathdatagen gen ./models/*.dgdatagen gen .  # Current directory2. “Build failed: Go compilation error”
Section titled “2. “Build failed: Go compilation error””Problem: Generated Go code has compilation errors.
Common causes:
- Invalid Go syntax in generation functions
 - Missing imports
 - Type mismatches
 
Solution: Check your generation functions for Go syntax errors.
// Wrong - invalid Go syntaxfunc name() {  return Name(  // Missing closing parenthesis}
// Correctfunc name() {  return Name()}3. “Permission denied” or “Access denied”
Section titled “3. “Permission denied” or “Access denied””Problem: Cannot write to output directory.
Solutions:
# Check directory permissionsls -la output/
# Create directory if it doesn't existmkdir -p output/
# Use different output directorydatagen gen users.dg -o /tmp/output4. “Invalid output format”
Section titled “4. “Invalid output format””Problem: Unsupported output format specified.
Solution: Use supported formats.
# Supported formatsdatagen gen users.dg -f csvdatagen gen users.dg -f jsondatagen gen users.dg -f xmldatagen gen users.dg -f stdoutExecution Errors
Section titled “Execution Errors”Execution errors occur when running datagen exec command.
1. “Config file not found”
Section titled “1. “Config file not found””Problem: Configuration file doesn’t exist.
Solution: Create or specify correct config file.
# Create config.json{  "models": [...],  "sinks": [...]}
# Use config filedatagen exec users.dg --config config.json2. “Database connection failed”
Section titled “2. “Database connection failed””Problem: Cannot connect to database sink.
Common causes:
- Wrong connection details
 - Database not running
 - Network issues
 - Authentication problems
 
Solution: Check your database configuration.
{  "sinks": [    {      "sink_name": "mysql_sink",      "sink_type": "mysql",      "config": {        "host": "localhost",        "port": "3306",        "user": "root",        "password": "password",        "database": "testdb"      }    }  ]}3. “Model not found in config”
Section titled “3. “Model not found in config””Problem: Model referenced in config doesn’t exist.
Solution: Ensure model name matches exactly.
{  "models": [    {      "model_name": "users",      "target_sinks": ["mysql_sink"],      "count": 1000    }  ]}4. “Sink not found”
Section titled “4. “Sink not found””Problem: Model references a sink that doesn’t exist in config.
Solution: Define the sink in your config file.
{  "models": [    {      "model_name": "users",      "target_sinks": ["mysql_sink"]    }  ],  "sinks": [    {      "sink_name": "mysql_sink",      "sink_type": "mysql",      "config": {...}    }  ]}Common File Issues
Section titled “Common File Issues”1. “File not found”
Section titled “1. “File not found””Problem: Specified file doesn’t exist.
Solutions:
# Check if file existsls -la users.dg
# Use absolute pathdatagen gen /full/path/to/users.dg
# Use relative pathdatagen gen ./models/users.dg2. “Invalid file extension”
Section titled “2. “Invalid file extension””Problem: File doesn’t have .dg extension.
Solution: Rename file with correct extension.
# Rename filemv users.txt users.dgmv users users.dg3. “Empty model file”
Section titled “3. “Empty model file””Problem: Model file is empty or has no content.
Solution: Add model content.
// Minimum valid modelmodel users {  fields {    name() string  }
  gens {    func name() {      return Name()    }  }}