Explain type errors with library context #21

Open
opened 2026-01-05 21:16:14 +00:00 by mprihoda · 0 comments
mprihoda commented 2026-01-05 21:16:14 +00:00 (Migrated from github.com)

Problem

Scala/Java type errors can be cryptic, especially with libraries:

  • "No given instance of type Encoder[MyClass] was found"
  • "Cannot prove that List[A] =:= List[B]"
  • "value flatMap is not a member of Option[Int]"

Agent often doesn't know what the error means or how to fix it.

Proposed Solution

New Tool: explain_type_error

{
  "name": "explain_type_error",
  "description": "Explain a type error and suggest fixes",
  "input": {
    "errorMessage": "The compiler error message",
    "coordinates": "optional, library context",
    "scalaVersion": "optional"
  }
}

Example:

explain_type_error(
  "No given instance of type io.circe.Encoder[MyClass] was found",
  "io.circe::circe-generic:0.14.6"
)

Returns:

## Error Explained: Missing Circe Encoder

**What it means:**
Circe needs an \`Encoder[MyClass]\` to serialize your type to JSON, 
but one isn't available in implicit scope.

**Common fixes:**

1. **Derive automatically (recommended):**
\`\`\`scala
import io.circe.generic.semiauto._
case class MyClass(name: String, age: Int)
given Encoder[MyClass] = deriveEncoder
\`\`\`

2. **Use full auto-derivation:**
\`\`\`scala
import io.circe.generic.auto._
// Encoder derived automatically where needed
\`\`\`

3. **Write manually:**
\`\`\`scala
given Encoder[MyClass] = Encoder.instance { mc =>
  Json.obj("name" -> mc.name.asJson, "age" -> mc.age.asJson)
}
\`\`\`

**Required imports:**
\`\`\`scala
import io.circe.{Encoder, Json}
import io.circe.syntax._
\`\`\`

**Note:** All fields of \`MyClass\` must also have \`Encoder\` instances.

Implementation

  • Knowledge base of common error patterns per library
  • Pattern matching on error message text
  • Context-aware suggestions based on library

Error Categories

  1. Missing typeclass instance (Encoder, Decoder, Show, Eq)
  2. Type mismatch (wrong effect type, missing conversions)
  3. Missing import (extension methods, syntax)
  4. Constraint not satisfied (Sync, Concurrent, etc.)

Value for Agent

  • Quickly understands cryptic errors
  • Gets actionable fix suggestions
  • Learns common patterns for the library

Acceptance Criteria

  • Recognize common Circe errors (Encoder/Decoder)
  • Recognize cats/cats-effect typeclass errors
  • Provide import suggestions
  • Provide code fix examples
## Problem Scala/Java type errors can be cryptic, especially with libraries: - "No given instance of type Encoder[MyClass] was found" - "Cannot prove that List[A] =:= List[B]" - "value flatMap is not a member of Option[Int]" Agent often doesn't know what the error means or how to fix it. ## Proposed Solution ### New Tool: `explain_type_error` ```json { "name": "explain_type_error", "description": "Explain a type error and suggest fixes", "input": { "errorMessage": "The compiler error message", "coordinates": "optional, library context", "scalaVersion": "optional" } } ``` **Example:** ``` explain_type_error( "No given instance of type io.circe.Encoder[MyClass] was found", "io.circe::circe-generic:0.14.6" ) ``` **Returns:** ```markdown ## Error Explained: Missing Circe Encoder **What it means:** Circe needs an \`Encoder[MyClass]\` to serialize your type to JSON, but one isn't available in implicit scope. **Common fixes:** 1. **Derive automatically (recommended):** \`\`\`scala import io.circe.generic.semiauto._ case class MyClass(name: String, age: Int) given Encoder[MyClass] = deriveEncoder \`\`\` 2. **Use full auto-derivation:** \`\`\`scala import io.circe.generic.auto._ // Encoder derived automatically where needed \`\`\` 3. **Write manually:** \`\`\`scala given Encoder[MyClass] = Encoder.instance { mc => Json.obj("name" -> mc.name.asJson, "age" -> mc.age.asJson) } \`\`\` **Required imports:** \`\`\`scala import io.circe.{Encoder, Json} import io.circe.syntax._ \`\`\` **Note:** All fields of \`MyClass\` must also have \`Encoder\` instances. ``` ## Implementation - Knowledge base of common error patterns per library - Pattern matching on error message text - Context-aware suggestions based on library ## Error Categories 1. **Missing typeclass instance** (Encoder, Decoder, Show, Eq) 2. **Type mismatch** (wrong effect type, missing conversions) 3. **Missing import** (extension methods, syntax) 4. **Constraint not satisfied** (Sync, Concurrent, etc.) ## Value for Agent - Quickly understands cryptic errors - Gets actionable fix suggestions - Learns common patterns for the library ## Acceptance Criteria - [ ] Recognize common Circe errors (Encoder/Decoder) - [ ] Recognize cats/cats-effect typeclass errors - [ ] Provide import suggestions - [ ] Provide code fix examples
Sign in to join this conversation.
No description provided.