wavetermdev/waveterm · error

invalid input format: %w

Error message

invalid input format: %w

What it means

After the nil check, input is converted to builderWriteAppFileParams via utilfn.ReUnmarshal (marshal then unmarshal round-trip). Any shape mismatch — wrong types for fields, incompatible structures — surfaces here wrapped as "invalid input format: <underlying error>".

Source

Thrown at pkg/aiusechat/tools_builder.go:67

		}
	}

	return map[string]any{
		"build_success": result.Success,
		"build_error":   result.ErrorMessage,
		"build_output":  result.BuildOutput,
	}
}

func parseBuilderWriteAppFileInput(input any) (*builderWriteAppFileParams, error) {
	result := &builderWriteAppFileParams{}

	if input == nil {
		return nil, fmt.Errorf("input is required")
	}

	if err := utilfn.ReUnmarshal(result, input); err != nil {
		return nil, fmt.Errorf("invalid input format: %w", err)
	}

	if result.Contents == "" {
		return nil, fmt.Errorf("missing contents parameter")
	}

	return result, nil
}

func GetBuilderWriteAppFileToolDefinition(appId string, builderId string) uctypes.ToolDefinition {
	return uctypes.ToolDefinition{
		Name:        "builder_write_app_file",
		DisplayName: "Write App File",
		Description: fmt.Sprintf("Write the app.go file for app %s", appId),
		ToolLogName: "builder:write_app",
		Strict:      false,
		InputSchema: map[string]any{
			"type": "object",

View on GitHub (pinned to a4447c1563)

Solutions

  1. Read the wrapped %w cause to see the exact field/type mismatch and correct the tool arguments accordingly
  2. Ensure contents is a string (and any other params match their declared types)
  3. Verify client and library versions agree on the tool schema; update the SDK/model prompts if the schema changed

Example fix

// before
parseBuilderWriteAppFileInput(map[string]any{"contents": 12345})
// after
parseBuilderWriteAppFileInput(map[string]any{"contents": "file body text"})
Defensive patterns

Strategy: type-guard

Validate before calling

b, err := json.Marshal(input); if err != nil { return err }; var probe builderWriteAppFileParams; if err := json.Unmarshal(b, &probe); err != nil { return fmt.Errorf("invalid input format: %w", err) }

Type guard

func canUnmarshalWriteAppFile(input any) bool { var p builderWriteAppFileParams; return utilfn.ReUnmarshal(&p, input) == nil }

Try / catch

params, err := parseBuilderWriteAppFileInput(input); if err != nil && strings.HasPrefix(err.Error(), "invalid input format") { log.Printf("bad args: %v", err); return retryWithSchema(err) }

Prevention

When it happens

Trigger: Tool invoked with an object whose fields don't match builderWriteAppFileParams (e.g. "contents": 123, or nested structures that can't round-trip through JSON), causing ReUnmarshal to fail.

Common situations: Model emitting wrong-typed fields (number where string expected); inputs containing values unrepresentable in JSON (channels, funcs) when called from Go code; schema drift between client and library versions.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/839ac647aa484de9. Report an issue: GitHub.