fix: 捕获解析YAML时发生的错误
This commit is contained in:
parent
02f7ca63dc
commit
d3833fdfda
|
@ -10,7 +10,7 @@
|
||||||
<div class="control-zone">
|
<div class="control-zone">
|
||||||
<Space Size="@("0")">
|
<Space Size="@("0")">
|
||||||
<SpaceItem>
|
<SpaceItem>
|
||||||
<Button Type="@ButtonType.Text">
|
<Button Type="@ButtonType.Text" OnClick="@QuitButtontClicked">
|
||||||
退出
|
退出
|
||||||
</Button>
|
</Button>
|
||||||
</SpaceItem>
|
</SpaceItem>
|
||||||
|
@ -28,7 +28,9 @@
|
||||||
|
|
||||||
<div class="logging-zone">
|
<div class="logging-zone">
|
||||||
<AntList TItem="@string" DataSource="@_logs" Split="@false" @ref="@_logList">
|
<AntList TItem="@string" DataSource="@_logs" Split="@false" @ref="@_logList">
|
||||||
<p style="margin-bottom: 0">@context</p>
|
<ListItem class="logging-item">
|
||||||
|
<p>@context</p>
|
||||||
|
</ListItem>
|
||||||
</AntList>
|
</AntList>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -60,7 +62,7 @@
|
||||||
Log("未设置文法");
|
Log("未设置文法");
|
||||||
grammarText = string.Empty;
|
grammarText = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new StandaloneEditorConstructionOptions
|
return new StandaloneEditorConstructionOptions
|
||||||
{
|
{
|
||||||
Language = "yaml",
|
Language = "yaml",
|
||||||
|
@ -84,10 +86,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void QuitButtontClicked()
|
||||||
|
{
|
||||||
|
Navigation.NavigateTo("/", replace: true);
|
||||||
|
}
|
||||||
|
|
||||||
private void Log(string message)
|
private void Log(string message)
|
||||||
{
|
{
|
||||||
_logs.Add($"{DateTime.Now:HH:mm:ss} {message}");
|
_logs.Add($"{DateTime.Now:HH:mm:ss} {message}");
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -10,4 +10,9 @@
|
||||||
.logging-zone {
|
.logging-zone {
|
||||||
height: 15%;
|
height: 15%;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logging-item {
|
||||||
|
padding: 0 0 0;
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": false,
|
"launchBrowser": false,
|
||||||
"applicationUrl": "http://localhost:5163",
|
"applicationUrl": "http://localhost:5163",
|
||||||
|
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Katheryne.Abstractions;
|
using Katheryne.Abstractions;
|
||||||
|
using Katheryne.Exceptions;
|
||||||
using Katheryne.Models;
|
using Katheryne.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
|
@ -27,13 +28,26 @@ public class KatheryneChatRobotFactory
|
||||||
_defaultChatRobot = defaultChatRobot;
|
_defaultChatRobot = defaultChatRobot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置当前机器人使用的文法
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="grammarText">文法字符串</param>
|
||||||
|
/// <exception cref="GrammarException">编译文法失败抛出的异常</exception>
|
||||||
public void SetGrammar(string grammarText)
|
public void SetGrammar(string grammarText)
|
||||||
{
|
{
|
||||||
_factoryLogger.LogInformation("Receive new grammar: {}.", grammarText);
|
_factoryLogger.LogInformation("Receive new grammar: {}.", grammarText);
|
||||||
GrammarText = grammarText;
|
GrammarText = grammarText;
|
||||||
IDeserializer deserializer = _deserializerFactory.GetDeserializer();
|
IDeserializer deserializer = _deserializerFactory.GetDeserializer();
|
||||||
|
|
||||||
LexicalModel model = deserializer.Deserialize<LexicalModel>(grammarText);
|
LexicalModel model;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
model = deserializer.Deserialize<LexicalModel>(grammarText);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new GrammarException("Failed to parse lexical model.", ex);
|
||||||
|
}
|
||||||
_grammar = new Grammar(new GrammarTree(model), model.RobotName, model.BeginStageName);
|
_grammar = new Grammar(new GrammarTree(model), model.RobotName, model.BeginStageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user