From 31d82a3169205a2fb818b66516eb57b20099311c Mon Sep 17 00:00:00 2001 From: t0ng7u Date: Sun, 13 Jul 2025 00:16:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20fix:=20safeguard=20`NewAPIError.?= =?UTF-8?q?Error()`=20against=20nil=20pointer=20panic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backend • `types/error.go` – Return empty string when receiver itself is `nil`. – If `Err` is `nil`, fall back to `errorCode` string to avoid calling `nil.Error()`. This prevents runtime panics when the error handler builds an OpenAI-style error response but the underlying `Err` field has not been set. --- types/error.go | 7 +++++++ web/src/components/table/ChannelsTable.js | 4 ++-- web/src/components/table/LogsTable.js | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/types/error.go b/types/error.go index 7ef770ec..40d141cd 100644 --- a/types/error.go +++ b/types/error.go @@ -88,6 +88,13 @@ func (e *NewAPIError) GetErrorCode() ErrorCode { } func (e *NewAPIError) Error() string { + if e == nil { + return "" + } + if e.Err == nil { + // fallback message when underlying error is missing + return string(e.errorCode) + } return e.Err.Error() } diff --git a/web/src/components/table/ChannelsTable.js b/web/src/components/table/ChannelsTable.js index 19d759cd..3e089d6a 100644 --- a/web/src/components/table/ChannelsTable.js +++ b/web/src/components/table/ChannelsTable.js @@ -42,7 +42,7 @@ import { IconTreeTriangleDown, IconSearch, IconMore, - IconList, IconDescend2 + IconDescend2 } from '@douyinfe/semi-icons'; import { loadChannelModels, isMobile, copy } from '../../helpers'; import EditTagModal from '../../pages/Channel/EditTagModal.js'; @@ -630,7 +630,7 @@ const ChannelsTable = () => { >