Billionmail/BillionMail · error

error reading knowledge base: %v

Error message

error reading knowledge base: %v

What it means

ModifyKnowledgeBaseFile first loads the existing knowledge base via ReadKnowledgeBase before applying updates. This error wraps any failure from that read: the file does not exist, cannot be read, or contains invalid JSON. It means the knowledge base identified by (Domain, Kid) could not be loaded, so no modification occurred.

Source

Thrown at core/internal/service/askai/project.go:384

		Tid = GetUUID()
	}

	knowledge := KnowledgeInfo{
		Kid:        Tid,
		Title:      Title,
		Content:    Content,
		UpdateTime: public.GetNowTime(),
	}
	return SaveKnowledgeBase(Domain, knowledge)
}

// ModifyKnowledgeBaseFile updates the title and content of an existing knowledge base file.
// It reads the existing knowledge base, modifies the specified fields, and saves the updated knowledge base.
// If the knowledge base does not exist or cannot be read, it returns an error.
func ModifyKnowledgeBaseFile(Domain string, Kid string, Title string, Content string) error {
	knowledge, err := ReadKnowledgeBase(Domain, Kid)
	if err != nil {
		return fmt.Errorf("error reading knowledge base: %v", err)
	}

	// Update the knowledge base information
	if Title != "" {
		knowledge.Title = Title
	}
	if Content != "" {
		knowledge.Content = Content
	}

	knowledge.UpdateTime = public.GetNowTime()
	err = SaveKnowledgeBase(Domain, knowledge)
	if err != nil {
		return fmt.Errorf("error saving knowledge base: %v", err)
	}
	return nil
}

View on GitHub (pinned to fc36c76c05)

Solutions

  1. Verify the Kid matches an existing file: list PRODUCT_CONFIG_PATH/<domain>/knowledge/ and confirm <kid>.json exists
  2. Confirm the same Domain string is used for create, list, and modify calls
  3. If the file is corrupt, restore valid JSON or delete and recreate the knowledge base via CreateKnowledgeBaseFile
  4. Check file read permissions on the JSON file

Example fix

// before
ModifyKnowledgeBaseFile(domain, kid, title, content) // kid from stale cache
// after
if err := KnowledgeBaseExists(domain, kid); err != nil {
    return CreateKnowledgeBaseFile(domain, title, content, kid) // recreate if missing
}
return ModifyKnowledgeBaseFile(domain, kid, title, content)
Defensive patterns

Strategy: validation

Validate before calling

func knowledgeBaseExists(domain, kid string) bool {
    return public.FileExists(fmt.Sprintf(PRODUCT_CONFIG_PATH+"/%s/knowledge/%s.json", domain, kid))
}
// before ModifyKnowledgeBaseFile:
if !knowledgeBaseExists(domain, kid) {
    return fmt.Errorf("knowledge base %s not found for %s", kid, domain)
}

Try / catch

if err := ModifyKnowledgeBaseFile(domain, kid, title, content); err != nil {
    if strings.Contains(err.Error(), "reading knowledge base") {
        // treat as not-found: surface 404 to caller or recreate
    }
}

Prevention

When it happens

Trigger: ReadKnowledgeBase(Domain, Kid) returns an error because: no file exists at PRODUCT_CONFIG_PATH/<domain>/knowledge/<kid>.json (wrong Kid, wrong domain, or entry was deleted); the file is unreadable due to permissions; the JSON content is corrupt and fails to unmarshal (the inner 'error unmarshalling knowledge base').

Common situations: Client passes a stale Kid after the knowledge base was deleted; Kid casing or truncation mismatch (e.g. Kid derived from a filename split on '.'); domain mismatch between create and modify calls; file edited externally with invalid JSON.

Understand the failure class

Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.

Related errors


AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05). Data as JSON: /api/errors/d55b41b6ea7b4175. Report an issue: GitHub.