From 6854daec328d9048bfb765ef03a3759436d286e9 Mon Sep 17 00:00:00 2001 From: walon Date: Tue, 3 Aug 2021 18:48:24 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=20?= =?UTF-8?q?=E4=BB=8Eexcel=E9=87=8C=E8=AF=BB=E5=8F=96=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=BC=9A=E8=87=AA=E5=8A=A8=E6=B8=85=E7=90=86?= =?UTF-8?q?=E7=A9=BA=E7=99=BD=E5=AD=97=E7=AC=A6=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E6=84=8F=E5=A4=96=E5=86=99=E9=94=99=20=E3=80=90=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E3=80=91=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E6=97=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0'?= =?UTF-8?q?=E8=BE=B9=E7=95=8C=E7=AC=A6=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=8F=91?= =?UTF-8?q?=E7=8E=B0=E4=B8=80=E4=BA=9B=E5=A4=9A=E4=BD=99=E7=9A=84=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E5=AD=97=E7=AC=A6=E7=9A=84=E9=94=99=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/DataCreators/ExcelDataCreator.cs | 2 +- .../DataCreators/ExcelNamedRowDataCreator.cs | 8 +-- .../Source/DataCreators/JsonDataCreator.cs | 8 +-- .../Source/DataCreators/XmlDataCreator.cs | 4 +- .../Source/DataVisitors/ValidatorVisitor.cs | 2 +- src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs | 52 +++++++++---------- src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs | 8 +-- src/Luban.Job.Cfg/Source/Defs/DefBean.cs | 6 +-- src/Luban.Job.Cfg/Source/Defs/DefField.cs | 20 +++---- src/Luban.Job.Cfg/Source/Defs/DefTable.cs | 10 ++-- .../Source/Generate/CodeRenderBase.cs | 2 +- src/Luban.Job.Cfg/Source/Utils/DataUtil.cs | 2 +- src/Luban.Job.Cfg/Source/ValidatorContext.cs | 4 +- .../Source/Defs/DefAssemblyBase.cs | 10 ++-- .../Source/Defs/DefBeanBase.cs | 6 +-- src/Luban.Job.Common/Source/Defs/DefConst.cs | 8 +-- src/Luban.Job.Common/Source/Defs/DefEnum.cs | 14 ++--- .../Source/Defs/DefFieldBase.cs | 26 ++++++---- src/Luban.Job.Db/Source/Defs/DefAssembly.cs | 4 +- src/Luban.Job.Db/Source/Defs/DefBean.cs | 4 +- .../Source/Generate/AsyncCsRender.cs | 2 +- .../Source/Defs/DefAssembly.cs | 2 +- src/Luban.Job.Proto/Source/Defs/DefRpc.cs | 4 +- .../Source/Generate/CsRender.cs | 2 +- 24 files changed, 107 insertions(+), 103 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs index 3caa585..c5e6e3b 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs @@ -385,7 +385,7 @@ namespace Luban.Job.Cfg.DataCreators } else if (subType != DefBean.BEAN_NOT_NULL_STR && subType != originBean.Name) { - throw new Exception($"type:{type.Bean.FullName} 可空标识:{subType} 不合法(只能为{DefBean.BEAN_NOT_NULL_STR}或{DefBean.BEAN_NULL_STR}或{originBean.Name})"); + throw new Exception($"type:'{type.Bean.FullName}' 可空标识:'{subType}' 不合法(只能为{DefBean.BEAN_NOT_NULL_STR}或{DefBean.BEAN_NULL_STR}或{originBean.Name})"); } } return new DBean(originBean, originBean, CreateBeanFields(originBean, x, ass)); diff --git a/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs index be81748..56391e0 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs @@ -112,7 +112,7 @@ namespace Luban.Job.Cfg.DataCreators Sheet.Title title = row.GetTitle(fname); if (title == null) { - throw new Exception($"bean:{bean.FullName} 缺失 列:{fname},请检查是否写错或者遗漏"); + throw new Exception($"bean:'{bean.FullName}' 缺失 列:'{fname}',请检查是否写错或者遗漏"); } // 多级标题 if (title.SubTitles.Count > 0) @@ -208,7 +208,7 @@ namespace Luban.Job.Cfg.DataCreators { if (!type.IsNullable) { - throw new Exception($"type:{type} 不是可空类型 {type.Bean.FullName}? , 不能为空"); + throw new Exception($"type:'{type}' 不是可空类型 '{type.Bean.FullName}?' , 不能为空"); } return null; } @@ -216,7 +216,7 @@ namespace Luban.Job.Cfg.DataCreators DefBean implType = (DefBean)originBean.GetNotAbstractChildType(subType); if (implType == null) { - throw new Exception($"type:{fullType} 不是 bean 类型"); + throw new Exception($"type:'{fullType}' 不是 bean 类型"); } return new DBean(originBean, implType, CreateBeanFields(implType, row)); } @@ -231,7 +231,7 @@ namespace Luban.Job.Cfg.DataCreators } else if (subType != DefBean.BEAN_NOT_NULL_STR && subType != originBean.Name) { - throw new Exception($"type:{type.Bean.FullName} 可空标识:{subType} 不合法(只能为{DefBean.BEAN_NOT_NULL_STR}或{DefBean.BEAN_NULL_STR}或{originBean.Name})"); + throw new Exception($"type:'{type.Bean.FullName}' 可空标识:'{subType}' 不合法(只能为{DefBean.BEAN_NOT_NULL_STR}或{DefBean.BEAN_NULL_STR}或{originBean.Name})"); } } diff --git a/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs index bb86620..26f9c48 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs @@ -113,7 +113,7 @@ namespace Luban.Job.Cfg.DataCreators { if (!x.TryGetProperty(DefBean.TYPE_NAME_KEY, out var typeNameProp)) { - throw new Exception($"结构:{bean.FullName} 是多态类型,必须用 {DefBean.TYPE_NAME_KEY} 字段指定 子类名"); + throw new Exception($"结构:'{bean.FullName}' 是多态类型,必须用 '{DefBean.TYPE_NAME_KEY}' 字段指定 子类名"); } string subType = typeNameProp.GetString(); var fullName = TypeUtil.MakeFullName(bean.Namespace, subType); @@ -122,7 +122,7 @@ namespace Luban.Job.Cfg.DataCreators //{ // throw new Exception($"type:{fullName} 是抽象类. 不能创建实例"); //} - implBean = defType ?? throw new Exception($"type:{fullName} 不是合法类型"); + implBean = defType ?? throw new Exception($"type:'{fullName}' 不是合法类型"); } else { @@ -142,7 +142,7 @@ namespace Luban.Job.Cfg.DataCreators } else { - throw new Exception($"结构:{implBean.FullName} 字段:{f.Name} 不能 null or undefined "); + throw new Exception($"结构:'{implBean.FullName}' 字段:'{f.Name}' 不能 null or undefined "); } } else @@ -170,7 +170,7 @@ namespace Luban.Job.Cfg.DataCreators } else { - throw new Exception($"结构:{implBean.FullName} 字段:{f.Name} 缺失"); + throw new Exception($"结构:'{implBean.FullName}' 字段:'{f.Name}' 缺失"); } } return new DBean(bean, implBean, fields); diff --git a/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs index 9c2b6a5..53c6228 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs @@ -98,7 +98,7 @@ namespace Luban.Job.Cfg.DataCreators string subType = x.Attribute(DefBean.TYPE_NAME_KEY)?.Value; if (string.IsNullOrWhiteSpace(subType)) { - throw new Exception($"bean:{bean.FullName}是多态,需要指定{DefBean.TYPE_NAME_KEY}属性.\n xml:{x}"); + throw new Exception($"bean:'{bean.FullName}'是多态,需要指定{DefBean.TYPE_NAME_KEY}属性.\n xml:{x}"); } var fullName = TypeUtil.MakeFullName(bean.Namespace, subType); var defType = (DefBean)bean.GetNotAbstractChildType(subType); @@ -106,7 +106,7 @@ namespace Luban.Job.Cfg.DataCreators //{ // throw new Exception($"type:{fullName} 是抽象类. 不能创建实例"); //} - implBean = defType ?? throw new Exception($"type:{fullName} 不是合法类型"); + implBean = defType ?? throw new Exception($"type:'{fullName}' 不是合法类型"); } else { diff --git a/src/Luban.Job.Cfg/Source/DataVisitors/ValidatorVisitor.cs b/src/Luban.Job.Cfg/Source/DataVisitors/ValidatorVisitor.cs index 72e2cec..814fd70 100644 --- a/src/Luban.Job.Cfg/Source/DataVisitors/ValidatorVisitor.cs +++ b/src/Luban.Job.Cfg/Source/DataVisitors/ValidatorVisitor.cs @@ -198,7 +198,7 @@ namespace Luban.Job.Cfg.DataVisitors DType indexValue = ((DBean)value).Fields[indexOfIndexField]; if (!indexSet.Add(indexValue)) { - throw new Exception($"{TypeUtil.MakeFullName(_path)} index:{indexValue} 重复"); + throw new Exception($"'{TypeUtil.MakeFullName(_path)}' index:'{indexValue}' 重复"); } _path.Pop(); } diff --git a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs index 0065110..c79246b 100644 --- a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs +++ b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs @@ -83,7 +83,7 @@ namespace Luban.Job.Cfg.Defs } if (this._branches.Any(b => b.Name == branchName)) { - throw new Exception($"branch {branchName} 重复"); + throw new Exception($"branch '{branchName}' 重复"); } _branches.Add(new Branch(branchName)); } @@ -100,7 +100,7 @@ namespace Luban.Job.Cfg.Defs { if (_cfgGroups.Any(cg => cg.Names.Contains(g))) { - throw new Exception($"group名:{g} 重复"); + throw new Exception($"group名:'{g}' 重复"); } } @@ -131,7 +131,7 @@ namespace Luban.Job.Cfg.Defs var sepIndex = validatorStr.IndexOf(':'); if (sepIndex < 0) { - throw new Exception($"定义文件:{CurImportFile} 类型:{CurDefine} 字段:{e} key:{key} 不是合法的 validator 定义 (key1:value1#key2:value2 ...)"); + throw new Exception($"定义文件:{CurImportFile} 类型:'{CurDefine}' 字段:'{e}' key:'{key}' 不是合法的 validator 定义 (key1:value1#key2:value2 ...)"); } result.Add(new Validator() { Type = validatorStr[..sepIndex], Rule = validatorStr[(sepIndex + 1)..] }); } @@ -162,13 +162,13 @@ namespace Luban.Job.Cfg.Defs } default: { - throw new Exception($"service:{name} tag:{tagName} 非法"); + throw new Exception($"service:'{name}' tag:'{tagName}' 非法"); } } } if (!ValidGroup(groups, out var invalidGroup)) { - throw new Exception($"service:{name} group:{invalidGroup} 不存在"); + throw new Exception($"service:'{name}' group:'{invalidGroup}' 不存在"); } _cfgServices.Add(new Service() { Name = name, Manager = manager, Groups = groups, Refs = refs }); } @@ -204,7 +204,7 @@ namespace Luban.Job.Cfg.Defs { if (!string.IsNullOrWhiteSpace(indexStr)) { - throw new Exception($"定义文件:{CurImportFile} table:{tableName} mode=one 是单例表,不支持定义index属性"); + throw new Exception($"定义文件:{CurImportFile} table:'{tableName}' mode=one 是单例表,不支持定义index属性"); } mode = ETableMode.ONE; break; @@ -271,7 +271,7 @@ namespace Luban.Job.Cfg.Defs } else if (!ValidGroup(p.Groups, out var invalidGroup)) { - throw new Exception($"定义文件:{CurImportFile} table:{p.Name} group:{invalidGroup} 不存在"); + throw new Exception($"定义文件:{CurImportFile} table:'{p.Name}' group:'{invalidGroup}' 不存在"); } p.InputFiles.AddRange(input.Split(',')); @@ -282,12 +282,12 @@ namespace Luban.Job.Cfg.Defs var nameAndDirs = subBranchStr.Split(':'); if (nameAndDirs.Length != 2) { - throw new Exception($"定义文件:{CurImportFile} table:{p.Name} branch_input:{subBranchStr} 定义不合法"); + throw new Exception($"定义文件:{CurImportFile} table:'{p.Name}' branch_input:'{subBranchStr}' 定义不合法"); } var branchDirs = nameAndDirs[1].Split(',', ';').ToList(); if (!p.BranchInputFiles.TryAdd(nameAndDirs[0], branchDirs)) { - throw new Exception($"定义文件:{CurImportFile} table:{p.Name} branch_input:{subBranchStr} 子branch:{nameAndDirs[0]} 重复"); + throw new Exception($"定义文件:{CurImportFile} table:'{p.Name}' branch_input:'{subBranchStr}' 子branch:'{nameAndDirs[0]}' 重复"); } } } @@ -300,7 +300,7 @@ namespace Luban.Job.Cfg.Defs if (!_name2CfgTable.TryAdd(p.Name, p)) { var exist = _name2CfgTable[p.Name]; - throw new Exception($"定义文件:{CurImportFile} table:{p.Namespace}.{p.Name} 与 {exist.Namespace}.{exist.Name} 名称不能重复"); + throw new Exception($"定义文件:{CurImportFile} table:'{p.Namespace}.{p.Name}' 与 '{exist.Namespace}.{exist.Name}' 名称不能重复"); } _cfgTables.Add(p); } @@ -326,11 +326,11 @@ namespace Luban.Job.Cfg.Defs var cf = new CfgField() { Name = f.Name, Id = 0 }; - string[] attrs = attrRow[f.FromIndex].Value?.ToString().Split('&'); + string[] attrs = (attrRow[f.FromIndex].Value?.ToString() ?? "").Trim().Split('&').Select(s => s.Trim()).ToArray(); if (attrs.Length == 0 || string.IsNullOrWhiteSpace(attrs[0])) { - throw new Exception($"table:{table.Name} file:{file.OriginFile} title:{f.Name} type missing!"); + throw new Exception($"table:'{table.Name}' file:{file.OriginFile} title:'{f.Name}' type missing!"); } // 优先取desc行,如果为空,则取title行 @@ -352,10 +352,10 @@ namespace Luban.Job.Cfg.Defs var pair = attrs[i].Split('='); if (pair.Length != 2) { - throw new Exception($"table:{table.Name} file:{file.OriginFile} title:{f.Name} attr: '{attrs[i]}' is invalid!"); + throw new Exception($"table:'{table.Name}' file:{file.OriginFile} title:'{f.Name}' attr:'{attrs[i]}' is invalid!"); } - var attrName = pair[0]; - var attrValue = pair[1]; + var attrName = pair[0].Trim(); + var attrValue = pair[1].Trim(); switch (attrName) { case "index": @@ -399,7 +399,7 @@ namespace Luban.Job.Cfg.Defs } default: { - throw new Exception($"table:{table.Name} file:{file.OriginFile} title:{f.Name} attr: '{attrs[i]}' is invalid!"); + throw new Exception($"table:'{table.Name}' file:{file.OriginFile} title:'{f.Name}' attr:'{attrs[i]}' is invalid!"); } } } @@ -472,16 +472,16 @@ namespace Luban.Job.Cfg.Defs { DBean data = r.Data; //s_logger.Info("== read text:{}", r.Data); - string name = (data.GetField("name") as DString).Value; - string module = (data.GetField("module") as DString).Value; - string valueType = (data.GetField("value_type") as DString).Value; - string index = (data.GetField("index") as DString).Value; - string mode = (data.GetField("mode") as DString).Value; - string group = (data.GetField("group") as DString).Value; - string comment = (data.GetField("commnet") as DString).Value; + string name = (data.GetField("name") as DString).Value.Trim(); + string module = (data.GetField("module") as DString).Value.Trim(); + string valueType = (data.GetField("value_type") as DString).Value.Trim(); + string index = (data.GetField("index") as DString).Value.Trim(); + string mode = (data.GetField("mode") as DString).Value.Trim(); + string group = (data.GetField("group") as DString).Value.Trim(); + string comment = (data.GetField("commnet") as DString).Value.Trim(); bool isDefineFromExcel = (data.GetField("define_from_excel") as DBool).Value; - string inputFile = (data.GetField("input") as DString).Value; - string branchInput = (data.GetField("branch_input") as DString).Value; + string inputFile = (data.GetField("input") as DString).Value.Trim(); + string branchInput = (data.GetField("branch_input") as DString).Value.Trim(); AddTable(name, module, valueType, index, mode, group, comment, isDefineFromExcel, inputFile, branchInput); }; } @@ -523,7 +523,7 @@ namespace Luban.Job.Cfg.Defs } else if (!ValidGroup(f.Groups, out var invalidGroup)) { - throw new Exception($"定义文件:{CurImportFile} field:{e} group:{invalidGroup} 不存在"); + throw new Exception($"定义文件:{CurImportFile} field:'{e}' group:'{invalidGroup}' 不存在"); } f.Type = CreateType(e, "type"); diff --git a/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs b/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs index 3acad01..e7f45ea 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs @@ -100,7 +100,7 @@ namespace Luban.Job.Cfg.Defs { if (!CfgTables.TryAdd(table.FullName, table)) { - throw new Exception($"table:{table.FullName} duplicated"); + throw new Exception($"table:'{table.FullName}' duplicated"); } } @@ -143,11 +143,11 @@ namespace Luban.Job.Cfg.Defs { if (!this.Types.ContainsKey(refType)) { - throw new Exception($"service:{targetService.Name} ref:{refType} 类型不存在"); + throw new Exception($"service:'{targetService.Name}' ref:'{refType}' 类型不存在"); } if (!refTypes.TryAdd(refType, this.Types[refType])) { - throw new Exception($"service:{targetService.Name} ref:{refType} 重复引用"); + throw new Exception($"service:'{targetService.Name}' ref:'{refType}' 重复引用"); } } foreach ((var fullTypeName, var type) in this.Types) @@ -185,7 +185,7 @@ namespace Luban.Job.Cfg.Defs TargetBranch = defines.Branches.Find(b => b.Name == _branchName); if (TargetBranch == null) { - throw new Exception($"branch {_branchName} not in valid branch set"); + throw new Exception($"branch '{_branchName}' not in valid branch set"); } } diff --git a/src/Luban.Job.Cfg/Source/Defs/DefBean.cs b/src/Luban.Job.Cfg/Source/Defs/DefBean.cs index 0d8e6a9..7660db0 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefBean.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefBean.cs @@ -185,7 +185,7 @@ namespace Luban.Job.Cfg.Defs { if ((ParentDefType = (DefBean)AssemblyBase.GetDefType(Namespace, Parent)) == null) { - throw new Exception($"bean:{FullName} parent:{Parent} not exist"); + throw new Exception($"bean:'{FullName}' parent:'{Parent}' not exist"); } if (ParentDefType.Children == null) { @@ -210,7 +210,7 @@ namespace Luban.Job.Cfg.Defs HierarchyNotAbstractChildren = cs; if (Id != 0) { - throw new Exception($"bean:{FullName} beanid:{Id} should be 0!"); + throw new Exception($"bean:'{FullName}' beanid:{Id} should be 0!"); } else { @@ -222,7 +222,7 @@ namespace Luban.Job.Cfg.Defs { if (!string.IsNullOrWhiteSpace(c.Alias) && !nameOrAliasName.Add(c.Alias)) { - throw new Exception($"bean:{FullName} alias:{c.Alias} 重复"); + throw new Exception($"bean:'{FullName}' alias:{c.Alias} 重复"); } } DefField.CompileFields(this, HierarchyFields, false); diff --git a/src/Luban.Job.Cfg/Source/Defs/DefField.cs b/src/Luban.Job.Cfg/Source/Defs/DefField.cs index 818a48d..2cce437 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefField.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefField.cs @@ -168,7 +168,7 @@ namespace Luban.Job.Cfg.Defs { if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0) { - throw new Exception($"container element type can't be empty bean"); + throw new Exception($"container element type:'{e.Bean.FullName}' can't be empty bean"); } break; } @@ -176,7 +176,7 @@ namespace Luban.Job.Cfg.Defs { if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0) { - throw new Exception($"container element type can't be empty bean"); + throw new Exception($"container element type:'{e.Bean.FullName}' can't be empty bean"); } break; } @@ -197,19 +197,19 @@ namespace Luban.Job.Cfg.Defs { if ((IndexField = b.GetBeanAs().GetField(Index)) == null) { - throw new Exception($"type:{HostType.FullName} field:{Name} index:{Index}. index not exist"); + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' index:'{Index}'. index not exist"); } } else if ((CType is TList tlist) && (tlist.ElementType is TBean tb)) { if ((IndexField = tb.GetBeanAs().GetField(Index)) == null) { - throw new Exception($"type:{HostType.FullName} field:{Name} index:{Index}. index not exist"); + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' index:'{Index}'. index not exist"); } } else { - throw new Exception($"type:{HostType.FullName} field:{Name} index:{Index}. only array:bean or list:bean support index"); + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' index:'{Index}'. only array:bean or list:bean support index"); } } @@ -223,7 +223,7 @@ namespace Luban.Job.Cfg.Defs this.Remapper = AssemblyBase.GetDefTType(HostType.Namespace, this.RawDefine.Converter, this.IsNullable) as TEnum; if (this.Remapper == null) { - throw new Exception($"type:{HostType.FullName} field:{Name} converter:{this.RawDefine.Converter} not exists"); + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' converter:'{this.RawDefine.Converter}' not exists"); } } @@ -238,7 +238,7 @@ namespace Luban.Job.Cfg.Defs { if (val is RefValidator refValidator && !Assembly.GetCfgTable(refValidator.FirstTable).NeedExport) { - throw new Exception($"type:{HostType.FullName} field:{Name} ref 引用的表:{refValidator.FirstTable} 没有导出"); + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' ref 引用的表:'{refValidator.FirstTable}' 没有导出"); } } } @@ -259,12 +259,12 @@ namespace Luban.Job.Cfg.Defs { if (mapType.KeyType.GetType() != cfgTable.KeyTType.GetType()) { - throw new Exception($"type:{HostType.FullName} field:{Name} key类型:{mapType.KeyType.GetType()} 与 被引用的表:{cfgTable.FullName} key类型:{cfgTable.KeyTType.GetType()} 不一致"); + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' key类型:'{mapType.KeyType.GetType()}' 与 被引用的表:'{cfgTable.FullName}' key类型:'{cfgTable.KeyTType.GetType()}' 不一致"); } } else { - throw new Exception($"type:{HostType.FullName} field:{Name} 不是 map类型. 不能指定 key_validator 引用"); + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' 不是 map类型. 不能指定 key_validator 引用"); } } } @@ -288,7 +288,7 @@ namespace Luban.Job.Cfg.Defs if (valueType.GetType() != cfgTable.KeyTType.GetType()) { - throw new Exception($"type:{HostType.FullName} field:{Name} 类型:{valueType.GetType()} 与 被引用的表:{cfgTable.FullName} key类型:{cfgTable.KeyTType.GetType()} 不一致"); + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' 类型:'{valueType.GetType()}' 与 被引用的表:'{cfgTable.FullName}' key类型:'{cfgTable.KeyTType.GetType()}' 不一致"); } } diff --git a/src/Luban.Job.Cfg/Source/Defs/DefTable.cs b/src/Luban.Job.Cfg/Source/Defs/DefTable.cs index 63ccb89..932b09c 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefTable.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefTable.cs @@ -67,13 +67,13 @@ namespace Luban.Job.Cfg.Defs { if (ass.GetBranch(branchName) == null) { - throw new Exception($"table:{FullName} branch_input branch:{branchName} 不存在"); + throw new Exception($"table:'{FullName}' branch_input branch:'{branchName}' 不存在"); } } if ((ValueTType = (TBean)ass.CreateType(Namespace, ValueType)) == null) { - throw new Exception($"table:{FullName} 的 value类型:{ValueType} 不存在"); + throw new Exception($"table:'{FullName}' 的 value类型:'{ValueType}' 不存在"); } switch (Mode) @@ -94,12 +94,12 @@ namespace Luban.Job.Cfg.Defs } else { - throw new Exception($"table:{FullName} index:{Index} 字段不存在"); + throw new Exception($"table:'{FullName}' index:'{Index}' 字段不存在"); } } else if (ValueTType.Bean.HierarchyFields.Count == 0) { - throw new Exception($"table:{FullName} 必须定义至少一个字段"); + throw new Exception($"table:'{FullName}' 必须定义至少一个字段"); } else { @@ -110,7 +110,7 @@ namespace Luban.Job.Cfg.Defs KeyTType = IndexField.CType; break; } - default: throw new Exception($"unknown mode:{Mode}"); + default: throw new Exception($"unknown mode:'{Mode}'"); } } } diff --git a/src/Luban.Job.Cfg/Source/Generate/CodeRenderBase.cs b/src/Luban.Job.Cfg/Source/Generate/CodeRenderBase.cs index 62fbba1..41ada48 100644 --- a/src/Luban.Job.Cfg/Source/Generate/CodeRenderBase.cs +++ b/src/Luban.Job.Cfg/Source/Generate/CodeRenderBase.cs @@ -21,7 +21,7 @@ namespace Luban.Job.Cfg.Generate case DefEnum e: return Render(e); case DefBean b: return Render(b); case DefTable r: return Render(r); - default: throw new Exception($"unknown render type:{o}"); + default: throw new Exception($"unknown render type:'{o}'"); } } } diff --git a/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs b/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs index 1eb33c7..624187e 100644 --- a/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs +++ b/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs @@ -96,7 +96,7 @@ namespace Luban.Job.Cfg.Utils } if (key == "" && text != "") { - throw new Exception($"text keyΪ, text:{text}Ϊ"); + throw new Exception($"text keyΪ, text:'{text}'Ϊ"); } } diff --git a/src/Luban.Job.Cfg/Source/ValidatorContext.cs b/src/Luban.Job.Cfg/Source/ValidatorContext.cs index d6140ea..93d0cd3 100644 --- a/src/Luban.Job.Cfg/Source/ValidatorContext.cs +++ b/src/Luban.Job.Cfg/Source/ValidatorContext.cs @@ -220,7 +220,7 @@ namespace Luban.Job.Cfg DType key = r.Data.Fields[table.IndexFieldIdIndex]; if (!mainRecordMap.TryAdd(key, r)) { - throw new Exception($@"配置表 {table.FullName} 主文件 主键字段:{table.Index} 主键值:{key} 重复. + throw new Exception($@"配置表 '{table.FullName}' 主文件 主键字段:'{table.Index}' 主键值:'{key}' 重复. 记录1 来自文件:{r.Source} 记录2 来自文件:{mainRecordMap[key].Source} "); @@ -234,7 +234,7 @@ namespace Luban.Job.Cfg DType key = r.Data.Fields[table.IndexFieldIdIndex]; if (!branchRecordMap.TryAdd(key, r)) { - throw new Exception($@"配置表 {table.FullName} 分支文件 主键字段:{table.Index} 主键值:{key} 重复. + throw new Exception($@"配置表 '{table.FullName}' 分支文件 主键字段:'{table.Index}' 主键值:'{key}' 重复. 记录1 来自文件:{r.Source} 记录2 来自文件:{branchRecordMap[key].Source} "); diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index f40ca93..989bb11 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -46,7 +46,7 @@ namespace Luban.Job.Common.Defs string fullName = type.FullName; if (Types.ContainsKey(fullName)) { - throw new Exception($"type:{fullName} duplicate"); + throw new Exception($"type:'{fullName}' duplicate"); } Types.Add(fullName, type); } @@ -135,7 +135,7 @@ namespace Luban.Job.Common.Defs { if (!SupportNullable) { - throw new Exception($"not support nullable type:{module}.{type}"); + throw new Exception($"not support nullable type:'{module}.{type}'"); } nullable = true; type = type[0..^1]; @@ -173,7 +173,7 @@ namespace Luban.Job.Common.Defs } else { - throw new ArgumentException($"invalid type. module:{module} type:{type}"); + throw new ArgumentException($"invalid type. module:'{module}' type:'{type}'"); } } } @@ -184,7 +184,7 @@ namespace Luban.Job.Common.Defs string[] elementTypes = keyValueType.Split(',').Select(s => s.Trim()).ToArray(); if (elementTypes.Length != 2) { - throw new ArgumentException($"invalid map element type: {keyValueType}"); + throw new ArgumentException($"invalid map element type:'{keyValueType}'"); } return new TMap(CreateNotContainerType(module, elementTypes[0]), CreateNotContainerType(module, elementTypes[1]), isTreeMap); } @@ -205,7 +205,7 @@ namespace Luban.Job.Common.Defs case "hashmap": return CreateMapType(module, elementType, false); default: { - throw new ArgumentException($"invalid container type. module:{module} container:{containerType} element:{elementType}"); + throw new ArgumentException($"invalid container type. module:'{module}' container:'{containerType}' element:'{elementType}'"); } } } diff --git a/src/Luban.Job.Common/Source/Defs/DefBeanBase.cs b/src/Luban.Job.Common/Source/Defs/DefBeanBase.cs index fc7833d..153bf84 100644 --- a/src/Luban.Job.Common/Source/Defs/DefBeanBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefBeanBase.cs @@ -125,7 +125,7 @@ namespace Luban.Job.Common.Defs { if ((ParentDefType = (DefBeanBase)AssemblyBase.GetDefType(Namespace, Parent)) == null) { - throw new Exception($"bean:{FullName} parent:{Parent} not exist"); + throw new Exception($"bean:'{FullName}' parent:'{Parent}' not exist"); } if (ParentDefType.Children == null) { @@ -152,11 +152,11 @@ namespace Luban.Job.Common.Defs { if (c.Id <= 0) { - throw new Exception($"bean:{FullName} is child of dynamic type. beanid:{Id} can't less then 0!"); + throw new Exception($"bean:'{FullName}' is child of dynamic type. beanid:{Id} can't less then 0!"); } if (!ids.Add(c.Id)) { - throw new Exception($"bean:{c.FullName} beanid:{c.Id} duplicate!"); + throw new Exception($"bean:'{c.FullName}' beanid:{c.Id} duplicate!"); } } DefFieldBase.CompileFields(this, HierarchyFields, IsSerializeCompatible); diff --git a/src/Luban.Job.Common/Source/Defs/DefConst.cs b/src/Luban.Job.Common/Source/Defs/DefConst.cs index 4370244..8ccdbd4 100644 --- a/src/Luban.Job.Common/Source/Defs/DefConst.cs +++ b/src/Luban.Job.Common/Source/Defs/DefConst.cs @@ -43,19 +43,19 @@ namespace Luban.Job.Common.Defs { if (item.Name.Length == 0) { - throw new Exception($"{FullName} 常量字段名不能为空"); + throw new Exception($"'{FullName}' 常量字段名不能为空"); } if (!names.Add(item.Name)) { - throw new Exception($"{FullName} 字段名:{item.Name} 重复"); + throw new Exception($"'{FullName}' 字段名:'{item.Name}' 重复"); } if ((item.CType = AssemblyBase.CreateType(Namespace, item.Type)) == null) { - throw new Exception($"{FullName} type:{item.Type} 类型不存在"); + throw new Exception($"'{FullName}' type:'{item.Type}' 类型不存在"); } if (!item.CType.TryParseFrom(item.Value)) { - throw new Exception($"{FullName} value:{item.Value} 不是合法的 type:{item.Type} 类型值"); + throw new Exception($"'{FullName}' value:'{item.Value}' 不是合法的 type:'{item.Type}' 类型值"); } } } diff --git a/src/Luban.Job.Common/Source/Defs/DefEnum.cs b/src/Luban.Job.Common/Source/Defs/DefEnum.cs index ba2f6d3..cc84717 100644 --- a/src/Luban.Job.Common/Source/Defs/DefEnum.cs +++ b/src/Luban.Job.Common/Source/Defs/DefEnum.cs @@ -60,7 +60,7 @@ namespace Luban.Job.Common.Defs } else { - throw new Exception($"{name} 不是有效 枚举:{FullName} 值"); + throw new Exception($"'{name}' 不是有效 枚举:'{FullName}' 值"); } } @@ -89,7 +89,7 @@ namespace Luban.Job.Common.Defs string value = item.Value.ToLower(); if (!names.Add(item.Name)) { - throw new Exception($"enum:{fullName} 字段:{item.Name} 重复"); + throw new Exception($"enum:'{fullName}' 字段:'{item.Name}' 重复"); } if (string.IsNullOrEmpty(value)) { @@ -113,7 +113,7 @@ namespace Luban.Job.Common.Defs } else { - throw new Exception($"enum:{fullName} 枚举名:{item.Name} value:{item.Value} 非法"); + throw new Exception($"enum:'{fullName}' 枚举名:'{item.Name}' value:'{item.Value}' 非法"); } } else if (IsFlags) @@ -125,24 +125,24 @@ namespace Luban.Job.Common.Defs var index = Items.FindIndex(i => i.Name == n); if (index < 0) { - throw new Exception($"enum:{fullName} 枚举名:{item.Name} 值:{item.Value} 非法"); + throw new Exception($"enum:'{fullName}' 枚举名:'{item.Name}' 值:'{item.Value}' 非法"); } item.IntValue |= Items[index].IntValue; } } else { - throw new Exception($"enum:{fullName} 枚举名:{item.Name} value:{item.Value} 非法"); + throw new Exception($"enum:'{fullName}' 枚举名:'{item.Name}' value:'{item.Value}' 非法"); } if (!string.IsNullOrWhiteSpace(item.Name) && !_nameOrAlias2Value.TryAdd(item.Name, item.IntValue)) { - throw new Exception($"enum:{fullName} 枚举名:{Name} 重复"); + throw new Exception($"enum:'{fullName}' 枚举名:'{Name}' 重复"); } if (!string.IsNullOrWhiteSpace(item.Alias) && !_nameOrAlias2Value.TryAdd(item.Alias, item.IntValue)) { - throw new Exception($"enum:{fullName} 枚举名:{Name} alias:{item.Alias} 重复"); + throw new Exception($"enum:'{fullName}' 枚举名:'{Name}' alias:'{item.Alias}' 重复"); } } } diff --git a/src/Luban.Job.Common/Source/Defs/DefFieldBase.cs b/src/Luban.Job.Common/Source/Defs/DefFieldBase.cs index c5f13e4..17e60a6 100644 --- a/src/Luban.Job.Common/Source/Defs/DefFieldBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefFieldBase.cs @@ -85,16 +85,20 @@ namespace Luban.Job.Common.Defs if (Id < 0 || Id > 256) { - throw new Exception($"结构:{HostType.FullName} 字段:{Name} id:{Id} 超出范围"); + throw new Exception($"type:'{HostType.FullName}' field:'{Name}' id:{Id} 超出范围"); } if (!TypeUtil.IsValidName(Name)) { - throw new Exception($"filed name:{Name} is reserved"); + throw new Exception($"type:'{HostType.FullName}' filed name:'{Name}' is reserved"); } - if ((CType = AssemblyBase.CreateType(HostType.Namespace, Type)) == null) + try { - throw new Exception($"type:{HostType.FullName} filed:{Name} type:{Type} is invalid"); + CType = AssemblyBase.CreateType(HostType.Namespace, Type); + } + catch (Exception e) + { + throw new Exception($"type:'{HostType.FullName}' filed:'{Name}' type:'{Type}' is invalid", e); } //if (IsNullable && (CType.IsCollection || (CType is TBean))) @@ -108,7 +112,7 @@ namespace Luban.Job.Common.Defs { if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0) { - throw new Exception($"container element type can't be empty bean"); + throw new Exception($"container element type:'{e.Bean.FullName}' can't be empty bean"); } break; } @@ -116,7 +120,7 @@ namespace Luban.Job.Common.Defs { if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0) { - throw new Exception($"container element type can't be empty bean"); + throw new Exception($"container element type:'{e.Bean.FullName}' can't be empty bean"); } break; } @@ -137,11 +141,11 @@ namespace Luban.Job.Common.Defs { if (f.Id == 0) { - throw new Exception($"type:{hostType.FullName} field:{f.Name} id can't be 0"); + throw new Exception($"type:'{hostType.FullName}' field:'{f.Name}' id can't be 0"); } if (!ids.Add(f.Id)) { - throw new Exception($"type:{hostType.FullName} field:{f.Name} id:{f.Id} duplicate"); + throw new Exception($"type:'{hostType.FullName}' field:'{f.Name}' id:{f.Id} duplicate"); } } } @@ -152,15 +156,15 @@ namespace Luban.Job.Common.Defs var fname = f.Name; if (fname.Length == 0) { - throw new Exception($"type:{hostType.FullName} field id:{f.Id} name can't be empty"); + throw new Exception($"type:'{hostType.FullName}' field id:{f.Id} name can't be empty"); } if (!names.Add(fname)) { - throw new Exception($"type:{hostType.FullName} field:{fname} duplicate"); + throw new Exception($"type:'{hostType.FullName}' 'field:{fname}' duplicate"); } if (TypeUtil.ToCsStyleName(fname) == hostType.Name) { - throw new Exception($"type:{hostType.FullName} 字段:{fname} 生成的c#字段名与类型名相同,会引起编译错误"); + throw new Exception($"type:'{hostType.FullName}' field:'{fname}' 生成的c#字段名与类型名相同,会引起编译错误"); } } diff --git a/src/Luban.Job.Db/Source/Defs/DefAssembly.cs b/src/Luban.Job.Db/Source/Defs/DefAssembly.cs index c4bfa24..448c035 100644 --- a/src/Luban.Job.Db/Source/Defs/DefAssembly.cs +++ b/src/Luban.Job.Db/Source/Defs/DefAssembly.cs @@ -19,11 +19,11 @@ namespace Luban.Job.Db.Defs { if (!name2DbTables.TryAdd(table.FullName, table)) { - throw new Exception($"table:{table.FullName} duplicated"); + throw new Exception($"table:'{table.FullName}' duplicated"); } if (!id2DbTables.TryAdd(table.TableUId, table)) { - throw new Exception($"table:{table.FullName} 与 table:{id2DbTables[table.TableUId].FullName} id:{table.TableUId} duplicated"); + throw new Exception($"table:'{table.FullName}' 与 table:'{id2DbTables[table.TableUId].FullName}' id:{table.TableUId} duplicated"); } } diff --git a/src/Luban.Job.Db/Source/Defs/DefBean.cs b/src/Luban.Job.Db/Source/Defs/DefBean.cs index 9ae2bf5..a7f42d3 100644 --- a/src/Luban.Job.Db/Source/Defs/DefBean.cs +++ b/src/Luban.Job.Db/Source/Defs/DefBean.cs @@ -34,11 +34,11 @@ namespace Luban.Job.Db.Defs { if (c.Id == 0) { - throw new Exception($"bean:{FullName} is child of dynamic type. beanid:{Id} can't be 0!"); + throw new Exception($"bean:'{FullName}' is child of dynamic type. beanid:{Id} can't be 0!"); } if (!ids.Add(c.Id)) { - throw new Exception($"bean:{c.FullName} beanid:{c.Id} duplicate!"); + throw new Exception($"bean:'{c.FullName}' beanid:{c.Id} duplicate!"); } } diff --git a/src/Luban.Job.Db/Source/Generate/AsyncCsRender.cs b/src/Luban.Job.Db/Source/Generate/AsyncCsRender.cs index 9d2b187..63bbc82 100644 --- a/src/Luban.Job.Db/Source/Generate/AsyncCsRender.cs +++ b/src/Luban.Job.Db/Source/Generate/AsyncCsRender.cs @@ -17,7 +17,7 @@ namespace Luban.Job.Db.Generate case DefEnum e: return Render(e); case DefBean b: return Render(b); case DefTable p: return Render(p); - default: throw new Exception($"unknown render type:{o}"); + default: throw new Exception($"unknown render type:'{o}'"); } } diff --git a/src/Luban.Job.Proto/Source/Defs/DefAssembly.cs b/src/Luban.Job.Proto/Source/Defs/DefAssembly.cs index e208f4a..850f020 100644 --- a/src/Luban.Job.Proto/Source/Defs/DefAssembly.cs +++ b/src/Luban.Job.Proto/Source/Defs/DefAssembly.cs @@ -23,7 +23,7 @@ namespace Luban.Job.Proto.Defs { if (!id2Protos.TryAdd(proto.Id, proto)) { - throw new Exception($"proto:{proto.FullName} id:{proto.Id} duplicated with {id2Protos[proto.Id].FullName}"); + throw new Exception($"proto:'{proto.FullName}' id:{proto.Id} duplicated with '{id2Protos[proto.Id].FullName}'"); } } diff --git a/src/Luban.Job.Proto/Source/Defs/DefRpc.cs b/src/Luban.Job.Proto/Source/Defs/DefRpc.cs index d6b830e..66d37fb 100644 --- a/src/Luban.Job.Proto/Source/Defs/DefRpc.cs +++ b/src/Luban.Job.Proto/Source/Defs/DefRpc.cs @@ -39,12 +39,12 @@ namespace Luban.Job.Proto.Defs if ((TArgType = Assembly.CreateType(Namespace, ArgType)) == null) { - throw new Exception($"rpc name:{FullName} arg:{ArgType} is invalid"); + throw new Exception($"rpc name:'{FullName}' arg:{ArgType} is invalid"); } if ((TResType = Assembly.CreateType(Namespace, ResType)) == null) { - throw new Exception($"rpc name:{FullName} res:{ResType} is invalid"); + throw new Exception($"rpc name:'{FullName}' res:{ResType} is invalid"); } } } diff --git a/src/Luban.Job.Proto/Source/Generate/CsRender.cs b/src/Luban.Job.Proto/Source/Generate/CsRender.cs index 81f96c0..0e034c2 100644 --- a/src/Luban.Job.Proto/Source/Generate/CsRender.cs +++ b/src/Luban.Job.Proto/Source/Generate/CsRender.cs @@ -19,7 +19,7 @@ namespace Luban.Job.Proto.Generate case DefProto p: return Render(p); case DefRpc r: return Render(r); - default: throw new Exception($"unknown render type:{o}"); + default: throw new Exception($"unknown render type:'{o}'"); } }