alibaba/open-code-review · error

unmarshal test task config: %w

Error message

unmarshal test task config: %w

What it means

LoadDefault unmarshals the embedded testconnection task.json into a TestTask struct; this error wraps any JSON decode failure. Since the JSON is embedded at build time, this error almost always indicates a corrupted build artifact or a struct/JSON schema mismatch introduced by editing task.json or the Go types.

Source

Thrown at internal/config/testconnection/testconnection.go:37

type LlmConversation struct {
	Timeout  int           `json:"timeout"`
	Messages []ChatMessage `json:"messages"`
}

// ChatMessage represents a single message in a conversation.
type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

//go:embed task.json
var defaultTask []byte

// LoadDefault parses the embedded task.json and returns the TEST_TASK conversation.
func LoadDefault() (*LlmConversation, error) {
	var tasks TestTask
	if err := json.Unmarshal(defaultTask, &tasks); err != nil {
		return nil, fmt.Errorf("unmarshal test task config: %w", err)
	}
	return &tasks.TestTask, nil
}

func resolveLang(lang string) string {
	if lang == "" {
		return "English"
	}
	return lang
}

// ApplyLanguage injects a language directive into all system-role messages of this conversation.
func (c *LlmConversation) ApplyLanguage(lang string) {
	instruction := "\n\nAlways respond in " + resolveLang(lang) + "."
	for i := range c.Messages {
		if c.Messages[i].Role == "system" {
			c.Messages[i].Content += instruction
		}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Validate the embedded internal/config/testconnection/task.json with a JSON linter and fix syntax/type errors
  2. Align the TestTask struct fields/tags with the actual JSON schema
  3. Rebuild the binary cleanly to refresh the embedded asset
  4. Run the test connection command with the wrapped inner error (%w) visible to identify the exact JSON offset
Defensive patterns

Strategy: try-catch

Validate before calling

var probe json.RawMessage = defaultTask; var chk map[string]any; _ = json.Unmarshal(probe, &chk) // fails fast if embedded asset is corrupt

Try / catch

conv, err := testconnection.LoadDefault()
if err != nil {
    var unmarshalErr *json.UnmarshalTypeError
    if errors.As(err, &unmarshalErr) { /* schema mismatch: field %s */ }
    return fmt.Errorf("test-connection unavailable: %w", err)
}

Prevention

When it happens

Trigger: json.Unmarshal failing on the embedded defaultTask bytes inside LoadDefault(), called by runLLMTest (the test-connection CLI command).

Common situations: A developer edited embedded task.json and broke its JSON syntax or changed field types; struct tags in TestTask no longer match the JSON schema; a corrupted binary or a build system replacing the embedded asset.

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


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/8a18c18dac21631e. Report an issue: GitHub.