Skip to content

Commit 05a727c

Browse files
authored
lexlint: fix panic in breakingDefs when inner schema type changes (#1348)
## Summary - Fix panic in `breakingDefs` when comparing lexicon definitions whose inner schema types differ (e.g. `SchemaString` vs `SchemaObject`) - The type-change guard compared `reflect.TypeOf` on the `SchemaDef` wrapper structs, which are always the same type, so it never triggered — bare type assertions like `remote.Inner.(SchemaString)` then panicked - Fix by comparing `.Inner` field types instead - Add regression test ## Repro Any lexicon where a field changed type between versions (e.g. a `string` field becoming an `object`) triggers: ``` panic: interface conversion: interface {} is lexicon.SchemaObject, not lexicon.SchemaString goroutine 1 [running]: github.com/bluesky-social/indigo/lex/lexlint.breakingDefs(...) lex/lexlint/breaking.go:169 ```
2 parents 01fde70 + 621efef commit 05a727c

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

lex/lexlint/breaking.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ func breakingDefs(nsid syntax.NSID, name string, local, remote lexicon.SchemaDef
5555
issues := []LintIssue{}
5656

5757
// NOTE: in some situations this sort of change might actually be allowed?
58-
if reflect.TypeOf(local) != reflect.TypeOf(remote) {
58+
if reflect.TypeOf(local.Inner) != reflect.TypeOf(remote.Inner) {
5959
issues = append(issues, LintIssue{
6060
NSID: nsid,
6161
LintLevel: "error",
6262
LintName: "type-change",
6363
LintDescription: "schema definition type changed",
64-
Message: fmt.Sprintf("schema type changed (%s): %T != %T", name, local, remote),
64+
Message: fmt.Sprintf("schema type changed (%s): %T != %T", name, local.Inner, remote.Inner),
6565
})
6666
return issues
6767
}

lex/lexlint/breaking_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package lexlint
2+
3+
import (
4+
"testing"
5+
6+
"github.com/bluesky-social/indigo/atproto/lexicon"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestBreakingDefs_InnerTypeChange(t *testing.T) {
12+
assert := assert.New(t)
13+
14+
// When a field changes type (e.g. string -> object), breakingDefs should
15+
// report a type-change error rather than panicking on a type assertion.
16+
local := lexicon.SchemaDef{Inner: lexicon.SchemaString{}}
17+
remote := lexicon.SchemaDef{Inner: lexicon.SchemaObject{}}
18+
19+
issues := breakingDefs("com.example.test", "testField", local, remote)
20+
21+
assert.Len(issues, 1)
22+
assert.Equal("type-change", issues[0].LintName)
23+
assert.Equal("error", issues[0].LintLevel)
24+
}

0 commit comments

Comments
 (0)