@@ -17,28 +17,28 @@ namespace toml
1717 static ProxyGroupConfig from_toml (const value& v)
1818 {
1919 ProxyGroupConfig conf;
20- conf.Name = toml:: find<String>(v, " name" );
21- String type = toml:: find<String>(v, " type" );
22- String strategy = toml:: find_or<String>(v, " strategy" , " " );
20+ conf.Name = find<String>(v, " name" );
21+ String type = find<String>(v, " type" );
22+ String strategy = find_or<String>(v, " strategy" , " " );
2323 switch (hash_ (type))
2424 {
2525 case " select" _hash:
2626 conf.Type = ProxyGroupType::Select;
2727 break ;
2828 case " url-test" _hash:
2929 conf.Type = ProxyGroupType::URLTest;
30- conf.Url = toml:: find<String>(v, " url" );
31- conf.Interval = toml:: find<Integer>(v, " interval" );
32- conf.Tolerance = toml:: find_or<Integer>(v, " tolerance" , 0 );
30+ conf.Url = find<String>(v, " url" );
31+ conf.Interval = find<Integer>(v, " interval" );
32+ conf.Tolerance = find_or<Integer>(v, " tolerance" , 0 );
3333 if (v.contains (" lazy" ))
34- conf.Lazy = toml:: find_or<bool >(v, " lazy" , false );
34+ conf.Lazy = find_or<bool >(v, " lazy" , false );
3535 if (v.contains (" evaluate-before-use" ))
36- conf.EvaluateBeforeUse = toml:: find_or (v, " evaluate-before-use" , conf.EvaluateBeforeUse .get ());
36+ conf.EvaluateBeforeUse = find_or (v, " evaluate-before-use" , conf.EvaluateBeforeUse .get ());
3737 break ;
3838 case " load-balance" _hash:
3939 conf.Type = ProxyGroupType::LoadBalance;
40- conf.Url = toml:: find<String>(v, " url" );
41- conf.Interval = toml:: find<Integer>(v, " interval" );
40+ conf.Url = find<String>(v, " url" );
41+ conf.Interval = find<Integer>(v, " interval" );
4242 switch (hash_ (strategy))
4343 {
4444 case " consistent-hashing" _hash:
@@ -49,14 +49,14 @@ namespace toml
4949 break ;
5050 }
5151 if (v.contains (" persistent" ))
52- conf.Persistent = toml:: find_or (v, " persistent" , conf.Persistent .get ());
52+ conf.Persistent = find_or (v, " persistent" , conf.Persistent .get ());
5353 break ;
5454 case " fallback" _hash:
5555 conf.Type = ProxyGroupType::Fallback;
56- conf.Url = toml:: find<String>(v, " url" );
57- conf.Interval = toml:: find<Integer>(v, " interval" );
56+ conf.Url = find<String>(v, " url" );
57+ conf.Interval = find<Integer>(v, " interval" );
5858 if (v.contains (" evaluate-before-use" ))
59- conf.EvaluateBeforeUse = toml:: find_or (v, " evaluate-before-use" , conf.EvaluateBeforeUse .get ());
59+ conf.EvaluateBeforeUse = find_or (v, " evaluate-before-use" , conf.EvaluateBeforeUse .get ());
6060 break ;
6161 case " relay" _hash:
6262 conf.Type = ProxyGroupType::Relay;
@@ -66,24 +66,24 @@ namespace toml
6666 break ;
6767 case " smart" _hash:
6868 conf.Type = ProxyGroupType::Smart;
69- conf.Url = toml:: find<String>(v, " url" );
70- conf.Interval = toml:: find<Integer>(v, " interval" );
71- conf.Tolerance = toml:: find_or<Integer>(v, " tolerance" , 0 );
69+ conf.Url = find<String>(v, " url" );
70+ conf.Interval = find<Integer>(v, " interval" );
71+ conf.Tolerance = find_or<Integer>(v, " tolerance" , 0 );
7272 if (v.contains (" lazy" ))
73- conf.Lazy = toml:: find_or<bool >(v, " lazy" , false );
73+ conf.Lazy = find_or<bool >(v, " lazy" , false );
7474 if (v.contains (" evaluate-before-use" ))
75- conf.EvaluateBeforeUse = toml:: find_or (v, " evaluate-before-use" , conf.EvaluateBeforeUse .get ());
75+ conf.EvaluateBeforeUse = find_or (v, " evaluate-before-use" , conf.EvaluateBeforeUse .get ());
7676 break ;
7777 default :
78- throw toml::syntax_error ( " Proxy Group has incorrect type, should be one of following:\n select, url-test, load-balance, fallback, relay, ssid" , v.at (" type" ).location ());
78+ throw serialization_error ( format_error ( " Proxy Group has unsupported type! " , v. at ( " type " ). location (), " should be one of following: select, url-test, load-balance, fallback, relay, ssid" ) , v.at (" type" ).location ());
7979 }
80- conf.Timeout = toml:: find_or (v, " timeout" , 5 );
81- conf.Proxies = toml:: find_or<StrArray>(v, " rule" , {});
82- conf.UsingProvider = toml:: find_or<StrArray>(v, " use" , {});
80+ conf.Timeout = find_or (v, " timeout" , 5 );
81+ conf.Proxies = find_or<StrArray>(v, " rule" , {});
82+ conf.UsingProvider = find_or<StrArray>(v, " use" , {});
8383 if (conf.Proxies .empty () && conf.UsingProvider .empty ())
84- throw toml::syntax_error ( " Proxy Group must contains at least one of proxy match rule or provider" , v.location ());
84+ throw serialization_error ( format_error ( " Proxy Group must contains at least one of proxy match rule or provider! " , v. location (), " here " ) , v.location ());
8585 if (v.contains (" disable-udp" ))
86- conf.DisableUdp = toml:: find_or (v, " disable-udp" , conf.DisableUdp .get ());
86+ conf.DisableUdp = find_or (v, " disable-udp" , conf.DisableUdp .get ());
8787 return conf;
8888 }
8989 };
@@ -94,8 +94,8 @@ namespace toml
9494 static RulesetConfig from_toml (const value& v)
9595 {
9696 RulesetConfig conf;
97- conf.Group = toml:: find<String>(v, " group" );
98- String type = toml:: find_or<String>(v, " type" , " surge-ruleset" );
97+ conf.Group = find<String>(v, " group" );
98+ String type = find_or<String>(v, " type" , " surge-ruleset" );
9999 switch (hash_ (type))
100100 {
101101 /*
@@ -132,10 +132,10 @@ namespace toml
132132 conf.Url = type + " :" ;
133133 break ;
134134 default :
135- throw toml::syntax_error ( " Ruleset has incorrect type, should be one of following:\n surge-ruleset, quantumultx, clash-domain, clash-ipcidr, clash-classic" , v.at (" type" ).location ());
135+ throw serialization_error ( format_error ( " Ruleset has unsupported type! " , v. at ( " type " ). location (), " should be one of following: surge-ruleset, quantumultx, clash-domain, clash-ipcidr, clash-classic" ) , v.at (" type" ).location ());
136136 }
137- conf.Url += toml:: find<String>(v, " ruleset" );
138- conf.Interval = toml:: find_or<Integer>(v, " interval" , 86400 );
137+ conf.Url += find<String>(v, " ruleset" );
138+ conf.Interval = find_or<Integer>(v, " interval" , 86400 );
139139 return conf;
140140 }
141141 };
@@ -148,14 +148,14 @@ namespace toml
148148 RegexMatchConfig conf;
149149 if (v.contains (" script" ))
150150 {
151- conf.Script = toml:: find<String>(v, " script" );
151+ conf.Script = find<String>(v, " script" );
152152 return conf;
153153 }
154- conf.Match = toml:: find<String>(v, " match" );
154+ conf.Match = find<String>(v, " match" );
155155 if (v.contains (" emoji" ))
156- conf.Replace = toml:: find<String>(v, " emoji" );
156+ conf.Replace = find<String>(v, " emoji" );
157157 else
158- conf.Replace = toml:: find<String>(v, " replace" );
158+ conf.Replace = find<String>(v, " replace" );
159159 return conf;
160160 }
161161 };
@@ -166,10 +166,10 @@ namespace toml
166166 static CronTaskConfig from_toml (const value& v)
167167 {
168168 CronTaskConfig conf;
169- conf.Name = toml:: find<String>(v, " name" );
170- conf.CronExp = toml:: find<String>(v, " cronexp" );
171- conf.Path = toml:: find<String>(v, " path" );
172- conf.Timeout = toml:: find_or<Integer>(v, " timeout" , 0 );
169+ conf.Name = find<String>(v, " name" );
170+ conf.CronExp = find<String>(v, " cronexp" );
171+ conf.Path = find<String>(v, " path" );
172+ conf.Timeout = find_or<Integer>(v, " timeout" , 0 );
173173 return conf;
174174 }
175175 };
0 commit comments