【优化】优化读取excel数据的错误信息,给出准确的错误位置

main
walon 2021-10-25 16:36:39 +08:00
parent 8f872289b8
commit 1494bb9cf8
7 changed files with 44 additions and 175 deletions

View File

@ -214,6 +214,10 @@ namespace Luban.Job.Cfg.DataCreators
{
return null;
}
if (d == null)
{
throw new InvalidExcelDataException($"枚举值不能为空");
}
return new DEnum(type, d.ToString().Trim());
}

View File

@ -1,163 +0,0 @@
//using Luban.Job.Cfg.Datas;
//using Luban.Job.Cfg.DataSources.Excel;
//using Luban.Job.Cfg.Defs;
//using Luban.Job.Common.Types;
//using Luban.Job.Common.TypeVisitors;
//using System;
//using System.Collections.Generic;
//namespace Luban.Job.Cfg.DataCreators
//{
// class MultiRowExcelDataCreator : ITypeFuncVisitor<IEnumerable<ExcelStream>, bool, DefAssembly, DType>
// {
// public static MultiRowExcelDataCreator Ins { get; } = new MultiRowExcelDataCreator();
// public DType Accept(TBool type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TByte type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TShort type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TFshort type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TInt type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TFint type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TLong type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TFlong type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TFloat type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TDouble type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TEnum type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TString type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TBytes type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TText type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TBean type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// private List<DType> ReadMultiRow(TType type, IEnumerable<ExcelStream> rows, DefAssembly ass)
// {
// var list = new List<DType>();
// foreach (var stream in rows)
// {
// try
// {
// list.Add(type.Apply(ExcelStreamDataCreator.Ins, null, stream, ass));
// }
// catch (Exception e)
// {
// var dce = new DataCreateException(e, stream.LastReadDataInfo);
// throw dce;
// }
// }
// return list;
// }
// public DType Accept(TArray type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// return new DArray(type, ReadMultiRow(type.ElementType, x, ass));
// }
// public DType Accept(TList type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// return new DList(type, ReadMultiRow(type.ElementType, x, ass));
// }
// public DType Accept(TSet type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// return new DSet(type, ReadMultiRow(type.ElementType, x, ass));
// }
// public DType Accept(TMap type, IEnumerable<ExcelStream> rows, bool y, DefAssembly ass)
// {
// var map = new Dictionary<DType, DType>();
// foreach (var stream in rows)
// {
// try
// {
// DType key = type.KeyType.Apply(ExcelStreamDataCreator.Ins, null, stream, ass);
// DType value = type.ValueType.Apply(ExcelStreamDataCreator.Ins, null, stream, ass);
// map.Add(key, value);
// }
// catch (Exception e)
// {
// var dce = new DataCreateException(e, stream.LastReadDataInfo);
// throw dce;
// }
// }
// return new DMap(type, map);
// }
// public DType Accept(TVector2 type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TVector3 type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TVector4 type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// public DType Accept(TDateTime type, IEnumerable<ExcelStream> x, bool y, DefAssembly ass)
// {
// throw new NotImplementedException();
// }
// }
//}

View File

@ -196,6 +196,10 @@ namespace Luban.Job.Cfg.DataCreators
{
return null;
}
if (x == null)
{
throw new InvalidExcelDataException($"枚举值不能为空");
}
return new DEnum(type, x.ToString());
}
@ -291,7 +295,7 @@ namespace Luban.Job.Cfg.DataCreators
}
catch (Exception e)
{
var dce = new DataCreateException(e, $"字段:{fname}");
var dce = new DataCreateException(e, $"字段:{fname} 位置:{field.Location}");
dce.Push(bean, f);
throw dce;
}

View File

@ -38,6 +38,30 @@ namespace Luban.Job.Cfg.DataSources.Excel
public List<TitleRow> Elements { get; }
public string Location
{
get
{
if (Row != null)
{
return Row[SelfTitle.FromIndex].ToString();
}
if (Rows != null)
{
return Rows[0][SelfTitle.FromIndex].ToString();
}
if (Fields != null)
{
return Fields[SelfTitle.SubTitleList[0].Name].Location;
}
if (Elements != null)
{
return Elements.Count > 0 ? Elements[0].Location : "无法定位";
}
return "无法定位";
}
}
public ExcelStream AsStream(string sep)
{
if (string.IsNullOrEmpty(SelfTitle.Sep))

View File

@ -25,7 +25,7 @@ namespace Luban.Job.Common.Defs
ELanguage curLan = AssemblyBase.CurrentLanguage;
switch (AssemblyBase.NamingConventionBeanMember)
{
case NamingConvention.Origin: cn = Name; break;
case NamingConvention.None: cn = Name; break;
case NamingConvention.CameraCase: cn = TypeUtil.ToCamelCase(Name); break;
case NamingConvention.PascalCase: cn = TypeUtil.ToPascalCase(Name); break;
case NamingConvention.UnderScores: cn = TypeUtil.ToUnderScores(Name); break;

View File

@ -28,22 +28,22 @@ namespace Luban.Job.Common
[Option("use_unity_vector", Required = false, HelpText = "use UnityEngine.Vector{2,3,4}")]
public bool UseUnityVectors { get; set; }
[Option("naming_convention_module", Required = false, HelpText = "naming convention of module. can be language_recommend,origin,camelCase,PascalCase,under_scores")]
[Option("naming_convention_module", Required = false, HelpText = "naming convention of module. can be language_recommend,none,camelCase,PascalCase,under_scores")]
public string NamingConventionModuleStr { get; set; }
public NamingConvention NamingConventionModule { get; set; }
[Option("naming_convention_type", Required = false, HelpText = "naming convention of enum and bean. can be language_recommend,origin,camelCase,PascalCase,under_scores")]
[Option("naming_convention_type", Required = false, HelpText = "naming convention of enum and bean. can be language_recommend,none,camelCase,PascalCase,under_scores")]
public string NamingConventionTypeStr { get; set; }
public NamingConvention NamingConventionType { get; set; }
[Option("naming_convention_bean_member", Required = false, HelpText = "naming convention of bean member. can be language_recommend,origin,camelCase,PascalCase,under_scores")]
[Option("naming_convention_bean_member", Required = false, HelpText = "naming convention of bean member. can be language_recommend,none,camelCase,PascalCase,under_scores")]
public string NamingConventionBeanMemberStr { get; set; }
public NamingConvention NamingConventionBeanMember { get; set; }
[Option("naming_convention_enum_member", Required = false, HelpText = "naming convention of enum member. can be language_recommend,origin,camelCase,PascalCase,under_scores")]
[Option("naming_convention_enum_member", Required = false, HelpText = "naming convention of enum member. can be language_recommend,none,camelCase,PascalCase,under_scores")]
public string NamingConventionEnumMemberStr { get; set; }
public NamingConvention NamingConventionEnumMember { get; set; }
@ -70,7 +70,7 @@ namespace Luban.Job.Common
case null:
case "":
case "language_recommend": result = NamingConvention.LanguangeRecommend; return true;
case "origin": result = NamingConvention.Origin; return true;
case "none": result = NamingConvention.None; return true;
case "camelCase": result = NamingConvention.CameraCase; return true;
case "PascalCase": result = NamingConvention.PascalCase; return true;
case "under_scores": result = NamingConvention.UnderScores; return true;
@ -118,25 +118,25 @@ namespace Luban.Job.Common
{
if (!TryParseNamingConvention(NamingConventionModuleStr, out var m))
{
errMsg = "--naming_convention_module invalid! valid values: language_recommend,origin,camelCase,PascalCase,under_scores";
errMsg = "--naming_convention_module invalid! valid values: language_recommend,none,camelCase,PascalCase,under_scores";
return false;
}
NamingConventionModule = m;
if (!TryParseNamingConvention(NamingConventionTypeStr, out var t))
{
errMsg = "--naming_convention_type invalid! valid values: language_recommend,origin,camelCase,PascalCase,under_scores";
errMsg = "--naming_convention_type invalid! valid values: language_recommend,none,camelCase,PascalCase,under_scores";
return false;
}
NamingConventionType = t;
if (!TryParseNamingConvention(NamingConventionBeanMemberStr, out var bm))
{
errMsg = "--naming_convention_bean_member invalid! valid values: language_recommend,origin,camelCase,PascalCase,under_scores";
errMsg = "--naming_convention_bean_member invalid! valid values: language_recommend,none,camelCase,PascalCase,under_scores";
return false;
}
NamingConventionBeanMember = bm;
if (!TryParseNamingConvention(NamingConventionEnumMemberStr, out var em))
{
errMsg = "--naming_convention_enum_member invalid! valid values: language_recommend,origin,camelCase,PascalCase,under_scores";
errMsg = "--naming_convention_enum_member invalid! valid values: language_recommend,none,camelCase,PascalCase,under_scores";
return false;
}
NamingConventionEnumMember = em;

View File

@ -10,7 +10,7 @@ namespace Luban.Job.Common
{
Invalid,
LanguangeRecommend,
Origin,
None,
CameraCase,
PascalCase,
UnderScores,