Billionmail/BillionMail · error
error unmarshalling prompt config: %v
Error message
error unmarshalling prompt config: %v
What it means
GetPrompt reads PRODUCT_CONFIG_PATH/<Domain>/prompt_config.json into a PromptConfig struct. This error is wrapped when json.Unmarshal fails, meaning the file exists but its bytes are not valid JSON or do not match the PromptConfig shape (e.g. a JSON string where an object is expected). It is thrown so callers like ModifyPrompt fail fast instead of silently operating on a zero-value config.
Source
Thrown at core/internal/service/askai/project.go:807
if err != nil {
return PromptConfig{}, fmt.Errorf("error marshalling default prompt config: %v", err)
}
err = os.WriteFile(filename, defaultPromptJson, 0644)
if err != nil {
return PromptConfig{}, fmt.Errorf("error saving default prompt config file: %v", err)
}
return defaultPromptConfig, nil
}
data, err := os.ReadFile(filename)
if err != nil {
return PromptConfig{}, fmt.Errorf("error reading prompt config file: %v", err)
}
var config PromptConfig
err = json.Unmarshal(data, &config)
if err != nil {
return PromptConfig{}, fmt.Errorf("error unmarshalling prompt config: %v", err)
}
return config, nil
}
// ModifyPrompt updates the prompt configuration for a given domain.
// It reads the existing prompt configuration, modifies the specified fields, and saves the updated configuration back to the file.
// If the prompt is empty, it will not be updated.
func ModifyPrompt(Domain string, Prompt string) error {
config, err := GetPrompt(Domain)
if err != nil {
return fmt.Errorf("error getting prompt config: %v", err)
}
// Update the prompt configuration
if Prompt != "" {
config.Prompt = Prompt
}
View on GitHub (pinned to fc36c76c05)
Solutions
- Open PRODUCT_CONFIG_PATH/<Domain>/prompt_config.json and validate it with `jq .` or `python -m json.tool` to find the syntax error
- Fix the JSON manually or delete the file — GetPrompt recreates it from the default config on next call
- Ensure writes are atomic (write to temp file then os.Rename) to prevent truncated/partial configs
- Check the file has no UTF-8 BOM and is not empty
Example fix
// before
$ cat prompt_config.json
{"prompt": "Hello" // trailing comment breaks JSON
// after
$ cat prompt_config.json
{"prompt": "Hello", "update_time": 1725500000} Defensive patterns
Strategy: validation
Validate before calling
// validate the config file before calling GetPrompt
func validatePromptConfig(domain string) error {
data, err := os.ReadFile(fmt.Sprintf("%s/%s/prompt_config.json", PRODUCT_CONFIG_PATH, domain))
if err != nil {
return err // file missing: GetPrompt will create a default
}
if len(bytes.TrimPrefix(data, []byte{0xEF, 0xBB, 0xBF})) == 0 {
return errors.New("config file is empty")
}
var cfg map[string]any
return json.Unmarshal(data, &cfg) // syntax/shape check
} Type guard
func isValidPromptConfigJSON(data []byte) bool {
var cfg map[string]any
if err := json.Unmarshal(data, &cfg); err != nil {
return false
}
_, ok := cfg["prompt"]
return ok
} Try / catch
cfg, err := GetPrompt(domain)
if err != nil {
if strings.Contains(err.Error(), "unmarshalling") {
// corrupt file: reset to default
os.Remove(filepath.Join(PRODUCT_CONFIG_PATH, domain, "prompt_config.json"))
cfg, err = GetPrompt(domain)
}
if err != nil {
return err
}
} Prevention
- Validate prompt_config.json with jq after any manual edit
- Write config atomically (temp file + os.Rename) to avoid truncated files
- Add a startup check that every domain config parses, logging corrupt ones
- Never hand-edit configs on production without a JSON syntax check
When it happens
Trigger: Calling GetPrompt(domain) when prompt_config.json contains malformed JSON — truncated writes, manual edits with syntax errors, BOM bytes, or the file holding a JSON array/string instead of an object with a 'prompt' field.
Common situations: Someone hand-edited prompt_config.json and broke the syntax; a concurrent write was interrupted leaving a partial file; an upgrade changed the config schema; the file was overwritten with HTML/error output by another tool.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- error unmarshalling project configuration: %v
- error marshalling project configuration: %v
- error unmarshalling footer config: %v
- error marshalling footer config: %v
- error marshalling default prompt config: %v
AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05).
Data as JSON: /api/errors/e5b3fb333562266d.
Report an issue: GitHub.