Skip to content

Troubleshooting Guide

This guide helps you diagnose and resolve common issues when using datagen commands.

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.

users.dg
model users { // ✓ Correct - matches filename
// ...
}
// File: User.dg
model 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())
}

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.

// Wrong
fields {
name string // Missing parentheses and type
}
// Correct
fields {
name() string
}

Generation errors occur when running datagen gen command.

Problem: No model files found in the specified directory.

Solutions:

Terminal window
# Check current directory
pwd
# List .dg files
ls -la *.dg
# Use correct path
datagen gen ./models/*.dg
datagen gen . # Current directory

2. “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 syntax
func name() {
return Name( // Missing closing parenthesis
}
// Correct
func name() {
return Name()
}

3. “Permission denied” or “Access denied”

Section titled “3. “Permission denied” or “Access denied””

Problem: Cannot write to output directory.

Solutions:

Terminal window
# Check directory permissions
ls -la output/
# Create directory if it doesn't exist
mkdir -p output/
# Use different output directory
datagen gen users.dg -o /tmp/output

Problem: Unsupported output format specified.

Solution: Use supported formats.

Terminal window
# Supported formats
datagen gen users.dg -f csv
datagen gen users.dg -f json
datagen gen users.dg -f xml
datagen gen users.dg -f stdout

Execution errors occur when running datagen exec command.

Problem: Configuration file doesn’t exist.

Solution: Create or specify correct config file.

Terminal window
# Create config.json
{
"models": [...],
"sinks": [...]
}
# Use config file
datagen exec users.dg --config config.json

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"
}
}
]
}

Problem: Model referenced in config doesn’t exist.

Solution: Ensure model name matches exactly.

{
"models": [
{
"model_name": "users",
"target_sinks": ["mysql_sink"],
"count": 1000
}
]
}

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": {...}
}
]
}

Problem: Specified file doesn’t exist.

Solutions:

Terminal window
# Check if file exists
ls -la users.dg
# Use absolute path
datagen gen /full/path/to/users.dg
# Use relative path
datagen gen ./models/users.dg

Problem: File doesn’t have .dg extension.

Solution: Rename file with correct extension.

Terminal window
# Rename file
mv users.txt users.dg
mv users users.dg

Problem: Model file is empty or has no content.

Solution: Add model content.

// Minimum valid model
model users {
fields {
name() string
}
gens {
func name() {
return Name()
}
}
}