Skip to content

fix(knowledge): avoid panic on empty table raw content#2679

Open
MackDing wants to merge 1 commit intocoze-dev:mainfrom
MackDing:mack/fix-2619-knowledge-parse-panic
Open

fix(knowledge): avoid panic on empty table raw content#2679
MackDing wants to merge 1 commit intocoze-dev:mainfrom
MackDing:mack/fix-2619-knowledge-parse-panic

Conversation

@MackDing
Copy link
Copy Markdown

Problem

  • uploading or editing some knowledge-base table content could fail with code=105000005 and panic on index out of range [0] with length 0
  • root cause: packInsertData accessed slice.RawContent[0] without validating that RawContent existed and contained a valid table payload

Fix

  • guard against empty RawContent
  • guard against nil/non-table/empty table payload before dereferencing index 0
  • return typed business errors instead of panicking so the caller can fail gracefully
  • add focused tests covering empty payload, invalid payload, and valid table rows

Test

  • PATH=/home/clawos/work/.local-go/go/bin:$PATH GOPATH=/home/clawos/work/.gopath GOCACHE=/home/clawos/work/.gocache GOMODCACHE=/home/clawos/work/.gomodcache GOPROXY=https://proxy.golang.org,direct GOSUMDB=sum.golang.org GOFLAGS='-buildvcs=false -p=1' /home/clawos/work/.local-go/go/bin/go test -gcflags='all=-N -l' ./domain/knowledge/service -run 'Test(EventHandle|PackInsertData)' -count=1 -v

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 29, 2026

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@MackDing
Copy link
Copy Markdown
Author

Quick follow-up: this PR is ready on my side. If there is a preferred fix direction or any additional test / guard you’d like for the empty-table case, I’m happy to update it quickly. Thanks for reviewing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants