From dba19b1e66bde77305613af7eb6e0b9002d3b1bc Mon Sep 17 00:00:00 2001 From: "meilin.huang" <954537473@qq.com> Date: Sat, 18 Oct 2025 11:21:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20editor=E6=8F=90=E7=A4=BA=E8=A2=AB?= =?UTF-8?q?=E9=81=AE=E6=8C=A1=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/package.json | 8 ++++---- .../src/components/monaco/MonacoEditor.vue | 1 + frontend/src/layout/navMenu/horizontal.vue | 5 ++--- server/go.mod | 10 +++++----- server/internal/db/application/db.go | 4 ++-- .../internal/db/application/db_data_sync.go | 14 ++++++------- server/internal/db/application/db_sql_exec.go | 4 ++-- server/internal/db/application/db_transfer.go | 4 ++-- server/internal/db/dbm/dbi/db_info.go | 4 ++-- server/internal/db/dbm/dm/metadata.go | 2 +- server/internal/db/dbm/mssql/metadata.go | 2 +- server/internal/db/dbm/mysql/metadata.go | 2 +- server/internal/db/dbm/oracle/metadata.go | 2 +- server/internal/db/dbm/postgres/metadata.go | 2 +- server/internal/docker/api/container.go | 4 ++-- server/internal/es/esm/esi/es_info.go | 6 +++--- .../internal/machine/application/machine.go | 4 ++-- .../machine/application/machine_file.go | 4 ++-- .../machine/application/machine_term_op.go | 2 +- server/internal/machine/mcm/client.go | 2 +- server/internal/machine/mcm/machine.go | 2 +- server/internal/redis/application/redis.go | 2 +- server/internal/redis/rdm/info.go | 6 +++--- .../tag/application/resouce_auth_cert.go | 2 +- server/internal/tag/application/tag_tree.go | 2 +- server/pkg/biz/assert.go | 16 +++++++-------- server/pkg/errorx/bizerror.go | 20 ++++++++++++++----- 27 files changed, 73 insertions(+), 63 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 90686212..badf41b2 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -11,14 +11,14 @@ }, "dependencies": { "@element-plus/icons-vue": "^2.3.2", - "@logicflow/core": "^2.1.2", - "@logicflow/extension": "^2.1.3", + "@logicflow/core": "^2.1.3", + "@logicflow/extension": "^2.1.5", "@vueuse/core": "^13.9.0", "@xterm/addon-fit": "^0.10.0", "@xterm/addon-search": "^0.15.0", "@xterm/addon-web-links": "^0.11.0", "@xterm/xterm": "^5.5.0", - "asciinema-player": "^3.11.0", + "asciinema-player": "^3.11.1", "axios": "^1.6.2", "clipboard": "^2.0.11", "crypto-js": "^4.2.0", @@ -40,7 +40,7 @@ "uuid": "^13.0.0", "vue": "^v3.5.22", "vue-i18n": "^11.1.12", - "vue-router": "^4.5.1", + "vue-router": "^4.6.3", "vuedraggable": "^4.1.0" }, "devDependencies": { diff --git a/frontend/src/components/monaco/MonacoEditor.vue b/frontend/src/components/monaco/MonacoEditor.vue index c9463b05..ae0e9b4c 100644 --- a/frontend/src/components/monaco/MonacoEditor.vue +++ b/frontend/src/components/monaco/MonacoEditor.vue @@ -155,6 +155,7 @@ const defaultOptions = { scrollBeyondLastLine: false, lineNumbers: 'on', lineNumbersMinChars: 3, + fixedOverflowWidgets: true, // 使弹出层不被容器限制 } as editor.IStandaloneEditorConstructionOptions; const monacoTextareaRef: Ref = useTemplateRef('monacoTextareaRef'); diff --git a/frontend/src/layout/navMenu/horizontal.vue b/frontend/src/layout/navMenu/horizontal.vue index ded43ccd..8beb0ca9 100644 --- a/frontend/src/layout/navMenu/horizontal.vue +++ b/frontend/src/layout/navMenu/horizontal.vue @@ -138,9 +138,8 @@ onBeforeRouteUpdate((to) => { .horizontal-menu :deep(.el-sub-menu__title) { margin: 0 5px !important; justify-content: center; - max-width: 150px; - min-width: 120px; // 统一最小宽度 + width: fit-content; text-align: center; // 使文字居中对齐 - padding: 0 8px !important; // 统一内边距 + padding: 0 16px !important; // 统一内边距 } diff --git a/server/go.mod b/server/go.mod index ab6be902..29a6ee6b 100644 --- a/server/go.mod +++ b/server/go.mod @@ -34,8 +34,8 @@ require ( github.com/tidwall/gjson v1.18.0 github.com/veops/go-ansiterm v0.0.5 go.mongodb.org/mongo-driver/v2 v2.3.0 // mongo - golang.org/x/crypto v0.42.0 // ssh - golang.org/x/oauth2 v0.31.0 + golang.org/x/crypto v0.43.0 // ssh + golang.org/x/oauth2 v0.32.0 golang.org/x/sync v0.17.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 gopkg.in/yaml.v3 v3.0.1 @@ -118,9 +118,9 @@ require ( golang.org/x/exp v0.0.0-20251002181428-27f1f14c8bb9 // indirect golang.org/x/image v0.31.0 // indirect golang.org/x/mod v0.28.0 // indirect - golang.org/x/net v0.44.0 // indirect - golang.org/x/sys v0.36.0 // indirect - golang.org/x/text v0.29.0 // indirect + golang.org/x/net v0.45.0 // indirect + golang.org/x/sys v0.37.0 // indirect + golang.org/x/text v0.30.0 // indirect golang.org/x/tools v0.37.0 // indirect google.golang.org/protobuf v1.36.10 // indirect modernc.org/libc v1.66.10 // indirect diff --git a/server/internal/db/application/db.go b/server/internal/db/application/db.go index 6f020da0..3ab944a3 100644 --- a/server/internal/db/application/db.go +++ b/server/internal/db/application/db.go @@ -209,7 +209,7 @@ func (d *dbAppImpl) GetDbConnByInstanceId(ctx context.Context, instanceId uint64 return nil, errorx.NewBiz("failed to get database list") } if len(dbs) == 0 { - return nil, errorx.NewBiz("DB instance [%d] database is not configured, please configure it first", instanceId) + return nil, errorx.NewBizf("DB instance [%d] database is not configured, please configure it first", instanceId) } // 使用该实例关联的已配置数据库中的第一个库进行连接并返回 @@ -308,7 +308,7 @@ func (d *dbAppImpl) DumpDb(ctx context.Context, reqParam *dto.DumpDb) error { } if len(tbs) <= 0 { log(fmt.Sprintf("failed to get table [%s] information: No table information was retrieved", tableName)) - return errorx.NewBiz("Failed to get table information: %s", tableName) + return errorx.NewBizf("Failed to get table information: %s", tableName) } tableInfo := tbs[0] diff --git a/server/internal/db/application/db_data_sync.go b/server/internal/db/application/db_data_sync.go index 06632dec..5899d29e 100644 --- a/server/internal/db/application/db_data_sync.go +++ b/server/internal/db/application/db_data_sync.go @@ -114,7 +114,7 @@ func (app *dataSyncAppImpl) Run(ctx context.Context, id uint64) error { } updateStateTask.Id = id if err := app.UpdateById(ctx, updateStateTask); err != nil { - return errorx.NewBiz("failed to update task running state: %s", err.Error()) + return errorx.NewBizf("failed to update task running state: %s", err.Error()) } // 标记该任务运行中 @@ -184,20 +184,20 @@ func (app *dataSyncAppImpl) doDataSync(ctx context.Context, sql string, task *en srcConn, err := app.dbApp.GetDbConn(ctx, uint64(task.SrcDbId), task.SrcDbName) if err != nil { - return errorx.NewBiz("failed to connect to the source database: %s", err.Error()) + return errorx.NewBizf("failed to connect to the source database: %s", err.Error()) } // 获取目标数据库连接 targetConn, err := app.dbApp.GetDbConn(ctx, uint64(task.TargetDbId), task.TargetDbName) if err != nil { - return errorx.NewBiz("failed to connect to the target database: %s", err.Error()) + return errorx.NewBizf("failed to connect to the target database: %s", err.Error()) } // task.FieldMap为json数组字符串 [{"src":"id","target":"id"}],转为map var fieldMap []map[string]string err = json.Unmarshal([]byte(task.FieldMap), &fieldMap) if err != nil { - return errorx.NewBiz("there was an error parsing the field map json: %s", err.Error()) + return errorx.NewBizf("there was an error parsing the field map json: %s", err.Error()) } // 记录本次同步数据总数 @@ -213,7 +213,7 @@ func (app *dataSyncAppImpl) doDataSync(ctx context.Context, sql string, task *en targetTableColumns, err := targetConn.GetMetadata().GetColumns(task.TargetTableName) if err != nil { - return errorx.NewBiz("failed to get target table columns: %s", err.Error()) + return errorx.NewBizf("failed to get target table columns: %s", err.Error()) } targetColumnName2Column := collx.ArrayToMap(targetTableColumns, func(column dbi.Column) string { return column.ColumnName @@ -300,7 +300,7 @@ func (app *dataSyncAppImpl) srcData2TargetDb(srcRes []map[string]any, fieldMap [ // 开启本批次执行事务 targetDbTx, err := targetDbConn.Begin() if err != nil { - return errorx.NewBiz("failed to start the target database transaction: %s", err.Error()) + return errorx.NewBizf("failed to start the target database transaction: %s", err.Error()) } defer func() { if r := recover(); r != nil { @@ -320,7 +320,7 @@ func (app *dataSyncAppImpl) srcData2TargetDb(srcRes []map[string]any, fieldMap [ // 如果是mssql,暂不手动提交事务,否则报错 mssql: The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION. if err := targetDbTx.Commit(); err != nil { if targetDbConn.Info.Type != dbi.ToDbType("mssql") { - return errorx.NewBiz("data synchronization - The target database transaction failed to commit: %s", err.Error()) + return errorx.NewBizf("data synchronization - The target database transaction failed to commit: %s", err.Error()) } } diff --git a/server/internal/db/application/db_sql_exec.go b/server/internal/db/application/db_sql_exec.go index 65c0127f..f324ae0e 100644 --- a/server/internal/db/application/db_sql_exec.go +++ b/server/internal/db/application/db_sql_exec.go @@ -300,7 +300,7 @@ func (d *dbSqlExecAppImpl) FlowBizHandle(ctx context.Context, bizHandleParam *fl execSqlBizForm, err := jsonx.To[*FlowDbExecSqlBizForm](procinst.BizForm) if err != nil { - return nil, errorx.NewBiz("failed to parse the business form information: %s", err.Error()) + return nil, errorx.NewBizf("failed to parse the business form information: %s", err.Error()) } dbConn, err := d.dbApp.GetDbConn(ctx, execSqlBizForm.DbId, execSqlBizForm.DbName) @@ -471,7 +471,7 @@ func (d *dbSqlExecAppImpl) doUpdate(ctx context.Context, sqlExecParam *sqlExecPa nowRec++ res = append(res, row) if nowRec == maxRec { - return errorx.NewBiz("update SQL - the maximum number of updated queries is exceeded: %d", maxRec) + return errorx.NewBizf("update SQL - the maximum number of updated queries is exceeded: %d", maxRec) } return nil }) diff --git a/server/internal/db/application/db_transfer.go b/server/internal/db/application/db_transfer.go index 09cf7555..677bbe1c 100644 --- a/server/internal/db/application/db_transfer.go +++ b/server/internal/db/application/db_transfer.go @@ -122,12 +122,12 @@ func (app *dbTransferAppImpl) InitCronJob() { func (app *dbTransferAppImpl) Run(ctx context.Context, taskId uint64) (uint64, error) { if app.IsRunning(taskId) { - return 0, errorx.NewBiz("the db transfer task [%d] is running, please do not repeat the operation", taskId) + return 0, errorx.NewBizf("the db transfer task [%d] is running, please do not repeat the operation", taskId) } task, err := app.GetById(taskId) if err != nil { - return 0, errorx.NewBiz("db transfer task [%d] not found", taskId) + return 0, errorx.NewBizf("db transfer task [%d] not found", taskId) } logId, _ := app.CreateLog(ctx, taskId) diff --git a/server/internal/db/dbm/dbi/db_info.go b/server/internal/db/dbm/dbi/db_info.go index 8e01551d..70c69f61 100644 --- a/server/internal/db/dbm/dbi/db_info.go +++ b/server/internal/db/dbm/dbi/db_info.go @@ -70,13 +70,13 @@ func (di *DbInfo) Conn(ctx context.Context, meta Meta) (*DbConn, error) { conn, err := meta.GetSqlDb(ctx, di) if err != nil { logx.Errorf("db connection failed: %s:%d/%s, err:%s", di.Host, di.Port, database, err.Error()) - return nil, errorx.NewBiz("db connection failed: %s", err.Error()) + return nil, errorx.NewBizf("db connection failed: %s", err.Error()) } err = conn.Ping() if err != nil { logx.Errorf("db ping failed: %s:%d/%s, err:%s", di.Host, di.Port, database, err.Error()) - return nil, errorx.NewBiz("db connection failed: %s", err.Error()) + return nil, errorx.NewBizf("db connection failed: %s", err.Error()) } dbc := &DbConn{Id: GetDbConnId(di.Id, database), Info: di} diff --git a/server/internal/db/dbm/dm/metadata.go b/server/internal/db/dbm/dm/metadata.go index a1bdd250..7c8b8606 100644 --- a/server/internal/db/dbm/dm/metadata.go +++ b/server/internal/db/dbm/dm/metadata.go @@ -134,7 +134,7 @@ func (dd *DMMetadata) GetPrimaryKey(tablename string) (string, error) { return "", err } if len(columns) == 0 { - return "", errorx.NewBiz("[%s] 表不存在", tablename) + return "", errorx.NewBizf("[%s] 表不存在", tablename) } for _, v := range columns { if v.IsPrimaryKey { diff --git a/server/internal/db/dbm/mssql/metadata.go b/server/internal/db/dbm/mssql/metadata.go index 72d90ed3..5a5fcf3c 100644 --- a/server/internal/db/dbm/mssql/metadata.go +++ b/server/internal/db/dbm/mssql/metadata.go @@ -129,7 +129,7 @@ func (md *MssqlMetadata) GetPrimaryKey(tablename string) (string, error) { return "", err } if len(columns) == 0 { - return "", errorx.NewBiz("[%s] 表不存在", tablename) + return "", errorx.NewBizf("[%s] 表不存在", tablename) } for _, v := range columns { diff --git a/server/internal/db/dbm/mysql/metadata.go b/server/internal/db/dbm/mysql/metadata.go index 2950987b..ae4c1d69 100644 --- a/server/internal/db/dbm/mysql/metadata.go +++ b/server/internal/db/dbm/mysql/metadata.go @@ -125,7 +125,7 @@ func (md *MysqlMetadata) GetPrimaryKey(tablename string) (string, error) { return "", err } if len(columns) == 0 { - return "", errorx.NewBiz("[%s] 表不存在", tablename) + return "", errorx.NewBizf("[%s] 表不存在", tablename) } for _, v := range columns { diff --git a/server/internal/db/dbm/oracle/metadata.go b/server/internal/db/dbm/oracle/metadata.go index 2acd55c2..90f0616a 100644 --- a/server/internal/db/dbm/oracle/metadata.go +++ b/server/internal/db/dbm/oracle/metadata.go @@ -148,7 +148,7 @@ func (od *OracleMetadata) GetPrimaryKey(tablename string) (string, error) { return "", err } if len(columns) == 0 { - return "", errorx.NewBiz("[%s] 表不存在", tablename) + return "", errorx.NewBizf("[%s] 表不存在", tablename) } for _, v := range columns { if v.IsPrimaryKey { diff --git a/server/internal/db/dbm/postgres/metadata.go b/server/internal/db/dbm/postgres/metadata.go index 712da477..4c12c31b 100644 --- a/server/internal/db/dbm/postgres/metadata.go +++ b/server/internal/db/dbm/postgres/metadata.go @@ -124,7 +124,7 @@ func (pd *PgsqlMetadata) GetPrimaryKey(tablename string) (string, error) { return "", err } if len(columns) == 0 { - return "", errorx.NewBiz("[%s] 表不存在", tablename) + return "", errorx.NewBizf("[%s] 表不存在", tablename) } for _, v := range columns { if v.IsPrimaryKey { diff --git a/server/internal/docker/api/container.go b/server/internal/docker/api/container.go index c9959304..d1bdc2ba 100644 --- a/server/internal/docker/api/container.go +++ b/server/internal/docker/api/container.go @@ -148,14 +148,14 @@ func (d *Container) ContainerCreate(rc *req.Ctx) { if err != nil { _ = cli.DockerClient.ContainerRemove(ctx, containerCreate.Name, container.RemoveOptions{RemoveVolumes: true, Force: true}) - panic(errorx.NewBiz("create container failed, err: %v", err)) + panic(errorx.NewBizf("create container failed, err: %v", err)) } logx.Infof("create container %s successful! now check if the container is started and delete the container information if it is not.", containerCreate.Name) if err := cli.DockerClient.ContainerStart(ctx, con.ID, container.StartOptions{}); err != nil { _ = cli.DockerClient.ContainerRemove(ctx, containerCreate.Name, container.RemoveOptions{RemoveVolumes: true, Force: true}) - panic(errorx.NewBiz("create successful but start failed, err: %v", err)) + panic(errorx.NewBizf("create successful but start failed, err: %v", err)) } } diff --git a/server/internal/es/esm/esi/es_info.go b/server/internal/es/esm/esi/es_info.go index 55eae25d..19cfec60 100644 --- a/server/internal/es/esm/esi/es_info.go +++ b/server/internal/es/esm/esi/es_info.go @@ -58,14 +58,14 @@ func (di *EsInfo) Conn(ctx context.Context) (*EsConn, map[string]any, error) { err := di.IfUseSshTunnelChangeIpPort(ctx) if err != nil { logx.Errorf("es ssh failed: %s, err:%s", di.baseUrl, err.Error()) - return nil, nil, errorx.NewBiz("es ssh failed: %s", err.Error()) + return nil, nil, errorx.NewBizf("es ssh failed: %s", err.Error()) } // 尝试获取es版本信息,调用接口:get / res, err := di.Ping() if err != nil { logx.Errorf("es ping failed: %s, err:%s", di.baseUrl, err.Error()) - return nil, nil, errorx.NewBiz("es ping failed: %s", err.Error()) + return nil, nil, errorx.NewBizf("es ping failed: %s", err.Error()) } esc := &EsConn{Id: di.InstanceId, Info: di} @@ -111,7 +111,7 @@ func (di *EsInfo) ExecApi(method, path string, data any, timeoutSecond ...int) ( return request.PutObj(data).BodyToMap() } - return nil, errorx.NewBiz("不支持的请求方法: %s", method) + return nil, errorx.NewBizf("不支持的请求方法: %s", method) } diff --git a/server/internal/machine/application/machine.go b/server/internal/machine/application/machine.go index f1b9ce18..4708dfd7 100644 --- a/server/internal/machine/application/machine.go +++ b/server/internal/machine/application/machine.go @@ -312,10 +312,10 @@ func (m *machineAppImpl) ToMachineInfoById(machineId uint64) (*mcm.MachineInfo, func (m *machineAppImpl) getMachineAndAuthCert(machineId uint64) (*entity.Machine, *tagentity.ResourceAuthCert, error) { me, err := m.GetById(machineId) if err != nil { - return nil, nil, errorx.NewBiz("[%d] machine not found", machineId) + return nil, nil, errorx.NewBizf("[%d] machine not found", machineId) } if me.Status != entity.MachineStatusEnable && me.Protocol == 1 { - return nil, nil, errorx.NewBiz("[%s] machine has been disable", me.Code) + return nil, nil, errorx.NewBizf("[%s] machine has been disable", me.Code) } authCert, err := m.resourceAuthCertApp.GetResourceAuthCert(tagentity.TagTypeMachine, me.Code) diff --git a/server/internal/machine/application/machine_file.go b/server/internal/machine/application/machine_file.go index 4bba3666..f538539a 100644 --- a/server/internal/machine/application/machine_file.go +++ b/server/internal/machine/application/machine_file.go @@ -180,7 +180,7 @@ func (m *machineFileAppImpl) GetDirSize(ctx context.Context, opParam *dto.Machin //du: cannot access ‘/proc/19087/fdinfo/3’: No such file or directory\n //18G /\n if res == "" { - return "", errorx.NewBiz("failed to get directory size: %s", err.Error()) + return "", errorx.NewBizf("failed to get directory size: %s", err.Error()) } strs := strings.Split(res, "\n") res = strs[len(strs)-2] @@ -247,7 +247,7 @@ func (m *machineFileAppImpl) CreateFile(ctx context.Context, opParam *dto.Machin } file, err := sftpCli.Create(path) if err != nil { - return nil, errorx.NewBiz("failed to create file: %s", err.Error()) + return nil, errorx.NewBizf("failed to create file: %s", err.Error()) } defer file.Close() return mi, err diff --git a/server/internal/machine/application/machine_term_op.go b/server/internal/machine/application/machine_term_op.go index 99a839c4..b89dd1be 100644 --- a/server/internal/machine/application/machine_term_op.go +++ b/server/internal/machine/application/machine_term_op.go @@ -63,7 +63,7 @@ func (m *machineTermOpAppImpl) TermConn(ctx context.Context, cli *mcm.Cli, wsCon fileKey, wc, saveFileFunc, err := m.fileApp.NewWriter(ctx, "", fmt.Sprintf("mto_%d_%s.cast", termOpRecord.MachineId, timex.TimeNo())) if err != nil { - return errorx.NewBiz("failed to create a terminal playback log file: %v", err) + return errorx.NewBizf("failed to create a terminal playback log file: %v", err) } defer saveFileFunc(&err) diff --git a/server/internal/machine/mcm/client.go b/server/internal/machine/mcm/client.go index 96a6b94d..dd378044 100644 --- a/server/internal/machine/mcm/client.go +++ b/server/internal/machine/mcm/client.go @@ -63,7 +63,7 @@ func (c *Cli) GetSftpCli() (*sftp.Client, error) { if sftpclient == nil { sc, serr := sftp.NewClient(c.sshClient) if serr != nil { - return nil, errorx.NewBiz("failed to obtain the sftp client: %s", serr.Error()) + return nil, errorx.NewBizf("failed to obtain the sftp client: %s", serr.Error()) } sftpclient = sc c.sftpClient = sftpclient diff --git a/server/internal/machine/mcm/machine.go b/server/internal/machine/mcm/machine.go index 63d97194..4fbfdaea 100644 --- a/server/internal/machine/mcm/machine.go +++ b/server/internal/machine/mcm/machine.go @@ -56,7 +56,7 @@ func (mi *MachineInfo) Conn(ctx context.Context) (*Cli, error) { // 如果使用了ssh隧道,则修改机器ip port为暴露的ip port err := mi.IfUseSshTunnelChangeIpPort(ctx, false) if err != nil { - return nil, errorx.NewBiz("ssh tunnel connection failed: %s", err.Error()) + return nil, errorx.NewBizf("ssh tunnel connection failed: %s", err.Error()) } cli := &Cli{Info: mi} diff --git a/server/internal/redis/application/redis.go b/server/internal/redis/application/redis.go index c2f7965e..66b924e6 100644 --- a/server/internal/redis/application/redis.go +++ b/server/internal/redis/application/redis.go @@ -254,7 +254,7 @@ func (r *redisAppImpl) FlowBizHandle(ctx context.Context, bizHandleParam *flowap runCmdParam, err := jsonx.To[*FlowRedisRunCmdBizForm](procinst.BizForm) if err != nil { - return nil, errorx.NewBiz("failed to parse the business form information: %s", err.Error()) + return nil, errorx.NewBizf("failed to parse the business form information: %s", err.Error()) } redisConn, err := r.GetRedisConn(ctx, runCmdParam.Id, runCmdParam.Db) diff --git a/server/internal/redis/rdm/info.go b/server/internal/redis/rdm/info.go index 109a5ae9..539af439 100644 --- a/server/internal/redis/rdm/info.go +++ b/server/internal/redis/rdm/info.go @@ -70,7 +70,7 @@ func (re *RedisInfo) connStandalone() (*RedisConn, error) { _, e := cli.Ping(context.Background()).Result() if e != nil { cli.Close() - return nil, errorx.NewBiz("redis standalone connection failed: %s", e.Error()) + return nil, errorx.NewBizf("redis standalone connection failed: %s", e.Error()) } logx.Infof("redis standalone connection: %s/%d", re.Host, re.Db) @@ -95,7 +95,7 @@ func (re *RedisInfo) connCluster() (*RedisConn, error) { _, e := cli.Ping(context.Background()).Result() if e != nil { cli.Close() - return nil, errorx.NewBiz("redis cluster connection failed: %s", e.Error()) + return nil, errorx.NewBizf("redis cluster connection failed: %s", e.Error()) } logx.Infof("redis cluster connection: %s/%d", re.Host, re.Db) @@ -128,7 +128,7 @@ func (re *RedisInfo) connSentinel() (*RedisConn, error) { _, e := cli.Ping(context.Background()).Result() if e != nil { cli.Close() - return nil, errorx.NewBiz("redis sentinel connection failed: %s", e.Error()) + return nil, errorx.NewBizf("redis sentinel connection failed: %s", e.Error()) } logx.Infof("redis sentinel connection: %s/%d", re.Host, re.Db) diff --git a/server/internal/tag/application/resouce_auth_cert.go b/server/internal/tag/application/resouce_auth_cert.go index 0d49cb09..9862fa5f 100644 --- a/server/internal/tag/application/resouce_auth_cert.go +++ b/server/internal/tag/application/resouce_auth_cert.go @@ -121,7 +121,7 @@ func (r *resourceAuthCertAppImpl) RelateAuthCert(ctx context.Context, params *dt existNameAc := &entity.ResourceAuthCert{Name: addAcName} if r.GetByCond(existNameAc) == nil && existNameAc.ResourceCode != resourceCode { - return errorx.NewBiz("The name of the authorization credential cannot be repeated: [%s]", addAcName) + return errorx.NewBizf("The name of the authorization credential cannot be repeated: [%s]", addAcName) } addAuthCerts = append(addAuthCerts, addAc) diff --git a/server/internal/tag/application/tag_tree.go b/server/internal/tag/application/tag_tree.go index 6d65f67f..c8066f1b 100644 --- a/server/internal/tag/application/tag_tree.go +++ b/server/internal/tag/application/tag_tree.go @@ -210,7 +210,7 @@ func (p *tagTreeAppImpl) RelateTagsByCodeAndType(ctx context.Context, param *dto if len(parentTagCodePaths) == 0 { // 不满足满足条件的标签 - return errorx.NewBiz("There is no tag that satisfies [type=%d, code=%s]", parentTagType, parentTagCode) + return errorx.NewBizf("There is no tag that satisfies [type=%d, code=%s]", parentTagType, parentTagCode) } for _, tag := range param.Tags { diff --git a/server/pkg/biz/assert.go b/server/pkg/biz/assert.go index d690a47d..6575eb08 100644 --- a/server/pkg/biz/assert.go +++ b/server/pkg/biz/assert.go @@ -21,7 +21,7 @@ func ErrIsNil(err error, msgAndParams ...any) { panic(errorx.NewBiz(err.Error())) } - panic(errorx.NewBiz(msgAndParams[0].(string), msgAndParams[1:]...)) + panic(errorx.NewBizf(msgAndParams[0].(string), msgAndParams[1:]...)) } } @@ -43,7 +43,7 @@ func ErrIsNilI(ctx context.Context, err error, msgId i18n.MsgId, attrs ...any) { func ErrNotNil(err error, msg string, params ...any) { if err == nil { - panic(errorx.NewBiz(msg, params...)) + panic(errorx.NewBizf(msg, params...)) } } @@ -53,7 +53,7 @@ func ErrNotNil(err error, msg string, params ...any) { // biz.ErrIsNilAppendErr(err, "xxxx: %s") func ErrIsNilAppendErr(err error, msg string) { if err != nil { - panic(errorx.NewBiz(msg, err.Error())) + panic(errorx.NewBizf(msg, err.Error())) } } @@ -63,13 +63,13 @@ func ErrIsNilAppendErr(err error, msg string) { // biz.ErrIsNilAppendErr(err, "xxxx: %s") func ErrIsNilAppendErrI(ctx context.Context, err error, msgId i18n.MsgId) { if err != nil { - panic(errorx.NewBiz(i18n.TC(ctx, msgId), err.Error())) + panic(errorx.NewBizf(i18n.TC(ctx, msgId), err.Error())) } } func IsTrue(exp bool, msg string, params ...any) { if !exp { - panic(errorx.NewBiz(msg, params...)) + panic(errorx.NewBizf(msg, params...)) } } @@ -87,19 +87,19 @@ func IsTrueBy(exp bool, err *errorx.BizError) { func NotEmpty(str string, msg string, params ...any) { if str == "" { - panic(errorx.NewBiz(msg, params...)) + panic(errorx.NewBizf(msg, params...)) } } func NotNil(data any, msg string, params ...any) { if reflect.ValueOf(data).IsNil() { - panic(errorx.NewBiz(msg, params...)) + panic(errorx.NewBizf(msg, params...)) } } func NotBlank(data any, msg string, params ...any) { if anyx.IsBlank(data) { - panic(errorx.NewBiz(msg, params...)) + panic(errorx.NewBizf(msg, params...)) } } diff --git a/server/pkg/errorx/bizerror.go b/server/pkg/errorx/bizerror.go index 3de9acb6..096c1950 100644 --- a/server/pkg/errorx/bizerror.go +++ b/server/pkg/errorx/bizerror.go @@ -35,8 +35,13 @@ func (e BizError) String() string { } // NewBiz 创建业务逻辑错误结构体,默认为业务逻辑错误 -func NewBiz(msg string, formatValues ...any) *BizError { - return &BizError{code: BizErr.code, err: fmt.Sprintf(msg, formatValues...)} +func NewBiz(msg string) *BizError { + return &BizError{code: BizErr.code, err: msg} +} + +// NewBizf 创建业务逻辑错误结构体,可设置格式化参数 +func NewBizf(format string, formatValues ...any) *BizError { + return NewBiz(fmt.Sprintf(format, formatValues...)) } // NewBizI 使用i18n的msgId创建业务逻辑错误结构体,默认为业务逻辑错误 (使用ctx中的国际化语言) @@ -47,7 +52,12 @@ func NewBizI(ctx context.Context, msgId i18n.MsgId, attrs ...any) *BizError { return &BizError{code: BizErr.code, err: i18n.TC(ctx, msgId, attrs...)} } -// 创建业务逻辑错误结构体,可设置指定错误code -func NewBizCode(code int16, msg string, formats ...any) *BizError { - return &BizError{code: code, err: fmt.Sprintf(msg, formats...)} +// NewBizCode 创建业务逻辑错误结构体,可设置指定错误code +func NewBizCode(code int16, msg string) *BizError { + return &BizError{code: code, err: msg} +} + +// NewBizCodef 创建业务逻辑错误结构体,可设置指定错误code,并且支持格式化参数 +func NewBizCodef(code int16, format string, formats ...any) *BizError { + return NewBizCode(code, fmt.Sprintf(format, formats...)) }