【优化】 从excel里读取定义时,会自动清理空白字符,避免意外写错

【优化】日志打印字符串时,添加'边界符,方便发现一些多余的空白字符的错误。
main
walon 2021-08-03 18:48:24 +08:00
parent 05f98f3ae1
commit 6854daec32
24 changed files with 107 additions and 103 deletions

View File

@ -385,7 +385,7 @@ namespace Luban.Job.Cfg.DataCreators
} }
else if (subType != DefBean.BEAN_NOT_NULL_STR && subType != originBean.Name) 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)); return new DBean(originBean, originBean, CreateBeanFields(originBean, x, ass));

View File

@ -112,7 +112,7 @@ namespace Luban.Job.Cfg.DataCreators
Sheet.Title title = row.GetTitle(fname); Sheet.Title title = row.GetTitle(fname);
if (title == null) if (title == null)
{ {
throw new Exception($"bean:{bean.FullName} 缺失 列:{fname},请检查是否写错或者遗漏"); throw new Exception($"bean:'{bean.FullName}' 缺失 列:'{fname}',请检查是否写错或者遗漏");
} }
// 多级标题 // 多级标题
if (title.SubTitles.Count > 0) if (title.SubTitles.Count > 0)
@ -208,7 +208,7 @@ namespace Luban.Job.Cfg.DataCreators
{ {
if (!type.IsNullable) if (!type.IsNullable)
{ {
throw new Exception($"type:{type} 不是可空类型 {type.Bean.FullName}? , 不能为空"); throw new Exception($"type:'{type}' 不是可空类型 '{type.Bean.FullName}?' , 不能为空");
} }
return null; return null;
} }
@ -216,7 +216,7 @@ namespace Luban.Job.Cfg.DataCreators
DefBean implType = (DefBean)originBean.GetNotAbstractChildType(subType); DefBean implType = (DefBean)originBean.GetNotAbstractChildType(subType);
if (implType == null) if (implType == null)
{ {
throw new Exception($"type:{fullType} 不是 bean 类型"); throw new Exception($"type:'{fullType}' 不是 bean 类型");
} }
return new DBean(originBean, implType, CreateBeanFields(implType, row)); 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) 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})");
} }
} }

View File

@ -113,7 +113,7 @@ namespace Luban.Job.Cfg.DataCreators
{ {
if (!x.TryGetProperty(DefBean.TYPE_NAME_KEY, out var typeNameProp)) 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(); string subType = typeNameProp.GetString();
var fullName = TypeUtil.MakeFullName(bean.Namespace, subType); var fullName = TypeUtil.MakeFullName(bean.Namespace, subType);
@ -122,7 +122,7 @@ namespace Luban.Job.Cfg.DataCreators
//{ //{
// throw new Exception($"type:{fullName} 是抽象类. 不能创建实例"); // throw new Exception($"type:{fullName} 是抽象类. 不能创建实例");
//} //}
implBean = defType ?? throw new Exception($"type:{fullName} 不是合法类型"); implBean = defType ?? throw new Exception($"type:'{fullName}' 不是合法类型");
} }
else else
{ {
@ -142,7 +142,7 @@ namespace Luban.Job.Cfg.DataCreators
} }
else else
{ {
throw new Exception($"结构:{implBean.FullName} 字段:{f.Name} 不能 null or undefined "); throw new Exception($"结构:'{implBean.FullName}' 字段:'{f.Name}' 不能 null or undefined ");
} }
} }
else else
@ -170,7 +170,7 @@ namespace Luban.Job.Cfg.DataCreators
} }
else else
{ {
throw new Exception($"结构:{implBean.FullName} 字段:{f.Name} 缺失"); throw new Exception($"结构:'{implBean.FullName}' 字段:'{f.Name}' 缺失");
} }
} }
return new DBean(bean, implBean, fields); return new DBean(bean, implBean, fields);

View File

@ -98,7 +98,7 @@ namespace Luban.Job.Cfg.DataCreators
string subType = x.Attribute(DefBean.TYPE_NAME_KEY)?.Value; string subType = x.Attribute(DefBean.TYPE_NAME_KEY)?.Value;
if (string.IsNullOrWhiteSpace(subType)) 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 fullName = TypeUtil.MakeFullName(bean.Namespace, subType);
var defType = (DefBean)bean.GetNotAbstractChildType(subType); var defType = (DefBean)bean.GetNotAbstractChildType(subType);
@ -106,7 +106,7 @@ namespace Luban.Job.Cfg.DataCreators
//{ //{
// throw new Exception($"type:{fullName} 是抽象类. 不能创建实例"); // throw new Exception($"type:{fullName} 是抽象类. 不能创建实例");
//} //}
implBean = defType ?? throw new Exception($"type:{fullName} 不是合法类型"); implBean = defType ?? throw new Exception($"type:'{fullName}' 不是合法类型");
} }
else else
{ {

View File

@ -198,7 +198,7 @@ namespace Luban.Job.Cfg.DataVisitors
DType indexValue = ((DBean)value).Fields[indexOfIndexField]; DType indexValue = ((DBean)value).Fields[indexOfIndexField];
if (!indexSet.Add(indexValue)) if (!indexSet.Add(indexValue))
{ {
throw new Exception($"{TypeUtil.MakeFullName(_path)} index:{indexValue} 重复"); throw new Exception($"'{TypeUtil.MakeFullName(_path)}' index:'{indexValue}' 重复");
} }
_path.Pop(); _path.Pop();
} }

View File

@ -83,7 +83,7 @@ namespace Luban.Job.Cfg.Defs
} }
if (this._branches.Any(b => b.Name == branchName)) if (this._branches.Any(b => b.Name == branchName))
{ {
throw new Exception($"branch {branchName} 重复"); throw new Exception($"branch '{branchName}' 重复");
} }
_branches.Add(new Branch(branchName)); _branches.Add(new Branch(branchName));
} }
@ -100,7 +100,7 @@ namespace Luban.Job.Cfg.Defs
{ {
if (_cfgGroups.Any(cg => cg.Names.Contains(g))) 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(':'); var sepIndex = validatorStr.IndexOf(':');
if (sepIndex < 0) 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)..] }); result.Add(new Validator() { Type = validatorStr[..sepIndex], Rule = validatorStr[(sepIndex + 1)..] });
} }
@ -162,13 +162,13 @@ namespace Luban.Job.Cfg.Defs
} }
default: default:
{ {
throw new Exception($"service:{name} tag:{tagName} 非法"); throw new Exception($"service:'{name}' tag:'{tagName}' 非法");
} }
} }
} }
if (!ValidGroup(groups, out var invalidGroup)) 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 }); _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)) 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; mode = ETableMode.ONE;
break; break;
@ -271,7 +271,7 @@ namespace Luban.Job.Cfg.Defs
} }
else if (!ValidGroup(p.Groups, out var invalidGroup)) 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(',')); p.InputFiles.AddRange(input.Split(','));
@ -282,12 +282,12 @@ namespace Luban.Job.Cfg.Defs
var nameAndDirs = subBranchStr.Split(':'); var nameAndDirs = subBranchStr.Split(':');
if (nameAndDirs.Length != 2) 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(); var branchDirs = nameAndDirs[1].Split(',', ';').ToList();
if (!p.BranchInputFiles.TryAdd(nameAndDirs[0], branchDirs)) 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)) if (!_name2CfgTable.TryAdd(p.Name, p))
{ {
var exist = _name2CfgTable[p.Name]; 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); _cfgTables.Add(p);
} }
@ -326,11 +326,11 @@ namespace Luban.Job.Cfg.Defs
var cf = new CfgField() { Name = f.Name, Id = 0 }; 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])) 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行 // 优先取desc行如果为空,则取title行
@ -352,10 +352,10 @@ namespace Luban.Job.Cfg.Defs
var pair = attrs[i].Split('='); var pair = attrs[i].Split('=');
if (pair.Length != 2) 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 attrName = pair[0].Trim();
var attrValue = pair[1]; var attrValue = pair[1].Trim();
switch (attrName) switch (attrName)
{ {
case "index": case "index":
@ -399,7 +399,7 @@ namespace Luban.Job.Cfg.Defs
} }
default: 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; DBean data = r.Data;
//s_logger.Info("== read text:{}", r.Data); //s_logger.Info("== read text:{}", r.Data);
string name = (data.GetField("name") as DString).Value; string name = (data.GetField("name") as DString).Value.Trim();
string module = (data.GetField("module") as DString).Value; string module = (data.GetField("module") as DString).Value.Trim();
string valueType = (data.GetField("value_type") as DString).Value; string valueType = (data.GetField("value_type") as DString).Value.Trim();
string index = (data.GetField("index") as DString).Value; string index = (data.GetField("index") as DString).Value.Trim();
string mode = (data.GetField("mode") as DString).Value; string mode = (data.GetField("mode") as DString).Value.Trim();
string group = (data.GetField("group") as DString).Value; string group = (data.GetField("group") as DString).Value.Trim();
string comment = (data.GetField("commnet") as DString).Value; string comment = (data.GetField("commnet") as DString).Value.Trim();
bool isDefineFromExcel = (data.GetField("define_from_excel") as DBool).Value; bool isDefineFromExcel = (data.GetField("define_from_excel") as DBool).Value;
string inputFile = (data.GetField("input") as DString).Value; string inputFile = (data.GetField("input") as DString).Value.Trim();
string branchInput = (data.GetField("branch_input") as DString).Value; string branchInput = (data.GetField("branch_input") as DString).Value.Trim();
AddTable(name, module, valueType, index, mode, group, comment, isDefineFromExcel, inputFile, branchInput); 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)) 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"); f.Type = CreateType(e, "type");

View File

@ -100,7 +100,7 @@ namespace Luban.Job.Cfg.Defs
{ {
if (!CfgTables.TryAdd(table.FullName, table)) 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)) 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])) 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) 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); TargetBranch = defines.Branches.Find(b => b.Name == _branchName);
if (TargetBranch == null) if (TargetBranch == null)
{ {
throw new Exception($"branch {_branchName} not in valid branch set"); throw new Exception($"branch '{_branchName}' not in valid branch set");
} }
} }

View File

@ -185,7 +185,7 @@ namespace Luban.Job.Cfg.Defs
{ {
if ((ParentDefType = (DefBean)AssemblyBase.GetDefType(Namespace, Parent)) == null) 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) if (ParentDefType.Children == null)
{ {
@ -210,7 +210,7 @@ namespace Luban.Job.Cfg.Defs
HierarchyNotAbstractChildren = cs; HierarchyNotAbstractChildren = cs;
if (Id != 0) if (Id != 0)
{ {
throw new Exception($"bean:{FullName} beanid:{Id} should be 0!"); throw new Exception($"bean:'{FullName}' beanid:{Id} should be 0!");
} }
else else
{ {
@ -222,7 +222,7 @@ namespace Luban.Job.Cfg.Defs
{ {
if (!string.IsNullOrWhiteSpace(c.Alias) && !nameOrAliasName.Add(c.Alias)) 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); DefField.CompileFields(this, HierarchyFields, false);

View File

@ -168,7 +168,7 @@ namespace Luban.Job.Cfg.Defs
{ {
if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0) 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; break;
} }
@ -176,7 +176,7 @@ namespace Luban.Job.Cfg.Defs
{ {
if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0) 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; break;
} }
@ -197,19 +197,19 @@ namespace Luban.Job.Cfg.Defs
{ {
if ((IndexField = b.GetBeanAs<DefBean>().GetField(Index)) == null) if ((IndexField = b.GetBeanAs<DefBean>().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)) else if ((CType is TList tlist) && (tlist.ElementType is TBean tb))
{ {
if ((IndexField = tb.GetBeanAs<DefBean>().GetField(Index)) == null) if ((IndexField = tb.GetBeanAs<DefBean>().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 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; this.Remapper = AssemblyBase.GetDefTType(HostType.Namespace, this.RawDefine.Converter, this.IsNullable) as TEnum;
if (this.Remapper == null) 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) 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()) 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 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()) 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()}' 不一致");
} }
} }

View File

@ -67,13 +67,13 @@ namespace Luban.Job.Cfg.Defs
{ {
if (ass.GetBranch(branchName) == null) 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) if ((ValueTType = (TBean)ass.CreateType(Namespace, ValueType)) == null)
{ {
throw new Exception($"table:{FullName} 的 value类型:{ValueType} 不存在"); throw new Exception($"table:'{FullName}' 的 value类型:'{ValueType}' 不存在");
} }
switch (Mode) switch (Mode)
@ -94,12 +94,12 @@ namespace Luban.Job.Cfg.Defs
} }
else else
{ {
throw new Exception($"table:{FullName} index:{Index} 字段不存在"); throw new Exception($"table:'{FullName}' index:'{Index}' 字段不存在");
} }
} }
else if (ValueTType.Bean.HierarchyFields.Count == 0) else if (ValueTType.Bean.HierarchyFields.Count == 0)
{ {
throw new Exception($"table:{FullName} 必须定义至少一个字段"); throw new Exception($"table:'{FullName}' 必须定义至少一个字段");
} }
else else
{ {
@ -110,7 +110,7 @@ namespace Luban.Job.Cfg.Defs
KeyTType = IndexField.CType; KeyTType = IndexField.CType;
break; break;
} }
default: throw new Exception($"unknown mode:{Mode}"); default: throw new Exception($"unknown mode:'{Mode}'");
} }
} }
} }

View File

@ -21,7 +21,7 @@ namespace Luban.Job.Cfg.Generate
case DefEnum e: return Render(e); case DefEnum e: return Render(e);
case DefBean b: return Render(b); case DefBean b: return Render(b);
case DefTable r: return Render(r); case DefTable r: return Render(r);
default: throw new Exception($"unknown render type:{o}"); default: throw new Exception($"unknown render type:'{o}'");
} }
} }
} }

View File

@ -96,7 +96,7 @@ namespace Luban.Job.Cfg.Utils
} }
if (key == "" && text != "") if (key == "" && text != "")
{ {
throw new Exception($"text key为空, 但text:{text}不为空"); throw new Exception($"text key为空, 但text:'{text}'不为空");
} }
} }

View File

@ -220,7 +220,7 @@ namespace Luban.Job.Cfg
DType key = r.Data.Fields[table.IndexFieldIdIndex]; DType key = r.Data.Fields[table.IndexFieldIdIndex];
if (!mainRecordMap.TryAdd(key, r)) if (!mainRecordMap.TryAdd(key, r))
{ {
throw new Exception($@"配置表 {table.FullName} 主文件 主键字段:{table.Index} 主键值:{key} 重复. throw new Exception($@"配置表 '{table.FullName}' 主文件 主键字段:'{table.Index}' 主键值:'{key}' 重复.
1 :{r.Source} 1 :{r.Source}
2 :{mainRecordMap[key].Source} 2 :{mainRecordMap[key].Source}
"); ");
@ -234,7 +234,7 @@ namespace Luban.Job.Cfg
DType key = r.Data.Fields[table.IndexFieldIdIndex]; DType key = r.Data.Fields[table.IndexFieldIdIndex];
if (!branchRecordMap.TryAdd(key, r)) if (!branchRecordMap.TryAdd(key, r))
{ {
throw new Exception($@"配置表 {table.FullName} 分支文件 主键字段:{table.Index} 主键值:{key} 重复. throw new Exception($@"配置表 '{table.FullName}' 分支文件 主键字段:'{table.Index}' 主键值:'{key}' 重复.
1 :{r.Source} 1 :{r.Source}
2 :{branchRecordMap[key].Source} 2 :{branchRecordMap[key].Source}
"); ");

View File

@ -46,7 +46,7 @@ namespace Luban.Job.Common.Defs
string fullName = type.FullName; string fullName = type.FullName;
if (Types.ContainsKey(fullName)) if (Types.ContainsKey(fullName))
{ {
throw new Exception($"type:{fullName} duplicate"); throw new Exception($"type:'{fullName}' duplicate");
} }
Types.Add(fullName, type); Types.Add(fullName, type);
} }
@ -135,7 +135,7 @@ namespace Luban.Job.Common.Defs
{ {
if (!SupportNullable) if (!SupportNullable)
{ {
throw new Exception($"not support nullable type:{module}.{type}"); throw new Exception($"not support nullable type:'{module}.{type}'");
} }
nullable = true; nullable = true;
type = type[0..^1]; type = type[0..^1];
@ -173,7 +173,7 @@ namespace Luban.Job.Common.Defs
} }
else 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(); string[] elementTypes = keyValueType.Split(',').Select(s => s.Trim()).ToArray();
if (elementTypes.Length != 2) 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); 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); case "hashmap": return CreateMapType(module, elementType, false);
default: 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}'");
} }
} }
} }

View File

@ -125,7 +125,7 @@ namespace Luban.Job.Common.Defs
{ {
if ((ParentDefType = (DefBeanBase)AssemblyBase.GetDefType(Namespace, Parent)) == null) 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) if (ParentDefType.Children == null)
{ {
@ -152,11 +152,11 @@ namespace Luban.Job.Common.Defs
{ {
if (c.Id <= 0) 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)) 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); DefFieldBase.CompileFields(this, HierarchyFields, IsSerializeCompatible);

View File

@ -43,19 +43,19 @@ namespace Luban.Job.Common.Defs
{ {
if (item.Name.Length == 0) if (item.Name.Length == 0)
{ {
throw new Exception($"{FullName} 常量字段名不能为空"); throw new Exception($"'{FullName}' 常量字段名不能为空");
} }
if (!names.Add(item.Name)) 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) 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)) 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}' 类型值");
} }
} }
} }

View File

@ -60,7 +60,7 @@ namespace Luban.Job.Common.Defs
} }
else 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(); string value = item.Value.ToLower();
if (!names.Add(item.Name)) if (!names.Add(item.Name))
{ {
throw new Exception($"enum:{fullName} 字段:{item.Name} 重复"); throw new Exception($"enum:'{fullName}' 字段:'{item.Name}' 重复");
} }
if (string.IsNullOrEmpty(value)) if (string.IsNullOrEmpty(value))
{ {
@ -113,7 +113,7 @@ namespace Luban.Job.Common.Defs
} }
else else
{ {
throw new Exception($"enum:{fullName} 枚举名:{item.Name} value:{item.Value} 非法"); throw new Exception($"enum:'{fullName}' 枚举名:'{item.Name}' value:'{item.Value}' 非法");
} }
} }
else if (IsFlags) else if (IsFlags)
@ -125,24 +125,24 @@ namespace Luban.Job.Common.Defs
var index = Items.FindIndex(i => i.Name == n); var index = Items.FindIndex(i => i.Name == n);
if (index < 0) 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; item.IntValue |= Items[index].IntValue;
} }
} }
else 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)) 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)) 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}' 重复");
} }
} }
} }

View File

@ -85,16 +85,20 @@ namespace Luban.Job.Common.Defs
if (Id < 0 || Id > 256) 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)) 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))) //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) 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; break;
} }
@ -116,7 +120,7 @@ namespace Luban.Job.Common.Defs
{ {
if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0) 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; break;
} }
@ -137,11 +141,11 @@ namespace Luban.Job.Common.Defs
{ {
if (f.Id == 0) 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)) 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; var fname = f.Name;
if (fname.Length == 0) 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)) 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) if (TypeUtil.ToCsStyleName(fname) == hostType.Name)
{ {
throw new Exception($"type:{hostType.FullName} 字段:{fname} 生成的c#字段名与类型名相同,会引起编译错误"); throw new Exception($"type:'{hostType.FullName}' field:'{fname}' 生成的c#字段名与类型名相同,会引起编译错误");
} }
} }

View File

@ -19,11 +19,11 @@ namespace Luban.Job.Db.Defs
{ {
if (!name2DbTables.TryAdd(table.FullName, table)) 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)) 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");
} }
} }

View File

@ -34,11 +34,11 @@ namespace Luban.Job.Db.Defs
{ {
if (c.Id == 0) 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)) 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!");
} }
} }

View File

@ -17,7 +17,7 @@ namespace Luban.Job.Db.Generate
case DefEnum e: return Render(e); case DefEnum e: return Render(e);
case DefBean b: return Render(b); case DefBean b: return Render(b);
case DefTable p: return Render(p); case DefTable p: return Render(p);
default: throw new Exception($"unknown render type:{o}"); default: throw new Exception($"unknown render type:'{o}'");
} }
} }

View File

@ -23,7 +23,7 @@ namespace Luban.Job.Proto.Defs
{ {
if (!id2Protos.TryAdd(proto.Id, proto)) 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}'");
} }
} }

View File

@ -39,12 +39,12 @@ namespace Luban.Job.Proto.Defs
if ((TArgType = Assembly.CreateType(Namespace, ArgType)) == null) 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) 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");
} }
} }
} }

View File

@ -19,7 +19,7 @@ namespace Luban.Job.Proto.Generate
case DefProto p: return Render(p); case DefProto p: return Render(p);
case DefRpc r: return Render(r); case DefRpc r: return Render(r);
default: throw new Exception($"unknown render type:{o}"); default: throw new Exception($"unknown render type:'{o}'");
} }
} }