@@ -11,11 +11,13 @@ This Source Code Form is subject to the terms of the
1111using OneScript . Exceptions ;
1212using OneScript . Execution ;
1313using OneScript . Language ;
14+ using OneScript . Localization ;
1415using OneScript . StandardLibrary . Collections ;
1516using OneScript . StandardLibrary . NativeApi ;
1617using ScriptEngine ;
1718using ScriptEngine . Machine ;
1819using ScriptEngine . Machine . Contexts ;
20+ using System ;
1921
2022namespace OneScript . StandardLibrary
2123{
@@ -48,19 +50,9 @@ public void AttachScript(IBslProcess process, string path, string typeName)
4850 {
4951 _engine . AttachedScriptsFactory . AttachByPath ( compiler , path , typeName , process ) ;
5052 }
51- catch ( SyntaxErrorException e )
52- {
53- // обернем в RuntimeException
54- throw new RuntimeException (
55- Locale . NStr ( "ru = 'Ошибка компиляции подключаемого скрипта';en = 'Error compiling attached script'" ) ,
56- e ) ;
57- }
58- catch ( Compilation . CompilerException e )
59- {
60- // обернем в RuntimeException
61- throw new RuntimeException (
62- Locale . NStr ( "ru = 'Ошибка компиляции подключаемого скрипта';en = 'Error compiling attached script'" ) ,
63- e ) ;
53+ catch ( Exception e ) when ( e is SyntaxErrorException || e is CompilerException )
54+ {
55+ throw ScriptCompilingException ( e ) ;
6456 }
6557 }
6658
@@ -97,20 +89,10 @@ public UserScriptContextInstance LoadScriptFromString(IBslProcess process,
9789 try
9890 {
9991 return _engine . AttachedScriptsFactory . LoadFromString ( compiler , code , process , extData ) ;
100- }
101- catch ( SyntaxErrorException e )
102- {
103- // обернем в RuntimeException
104- throw new RuntimeException (
105- Locale . NStr ( "ru = 'Ошибка компиляции подключаемого скрипта';en = 'Error compiling attached script'" ) ,
106- e ) ;
107- }
108- catch ( CompilerException e )
109- {
110- // обернем в RuntimeException
111- throw new RuntimeException (
112- Locale . NStr ( "ru = 'Ошибка компиляции подключаемого скрипта';en = 'Error compiling attached script'" ) ,
113- e ) ;
92+ }
93+ catch ( Exception e ) when ( e is SyntaxErrorException || e is CompilerException )
94+ {
95+ throw ScriptCompilingException ( e ) ;
11496 }
11597 }
11698 }
@@ -128,22 +110,28 @@ public UserScriptContextInstance LoadScriptFromString(IBslProcess process,
128110 /// // В коде скрипта somescript.os будет доступна глобальная переменная "ЧислоПи"
129111 /// Объект = ЗагрузитьСценарий("somescript.os", Контекст);</example>
130112 [ ContextMethod ( "ЗагрузитьСценарий" , "LoadScript" ) ]
131- public IRuntimeContextInstance LoadScript ( IBslProcess process , string path , StructureImpl externalContext = null )
132- {
113+ public UserScriptContextInstance LoadScript ( IBslProcess process , string path , StructureImpl externalContext = null )
114+ {
133115 var compiler = _engine . GetCompilerService ( ) ;
134- if ( externalContext == null )
135- return _engine . AttachedScriptsFactory . LoadFromPath ( compiler , path , process ) ;
136- else
137- {
138- ExternalContextData extData = new ExternalContextData ( ) ;
139-
140- foreach ( var item in externalContext )
116+ try
117+ {
118+ if ( externalContext == null )
119+ return _engine . AttachedScriptsFactory . LoadFromPath ( compiler , path , process ) ;
120+ else
141121 {
142- extData . Add ( item . Key . ToString ( ) ! , item . Value ) ;
143- }
122+ ExternalContextData extData = new ExternalContextData ( ) ;
144123
145- return _engine . AttachedScriptsFactory . LoadFromPath ( compiler , path , extData , process ) ;
124+ foreach ( var item in externalContext )
125+ {
126+ extData . Add ( item . Key . ToString ( ) ! , item . Value ) ;
127+ }
146128
129+ return _engine . AttachedScriptsFactory . LoadFromPath ( compiler , path , extData , process ) ;
130+ }
131+ }
132+ catch ( Exception e ) when ( e is SyntaxErrorException || e is CompilerException )
133+ {
134+ throw ScriptCompilingException ( e ) ;
147135 }
148136 }
149137
@@ -189,5 +177,12 @@ public bool AttachAddIn(string dllPath, string name = "", NativeApiEnums type =
189177 return NativeApiFactory . Register ( dllPath , name , _engine . TypeManager ) ;
190178 }
191179 }
180+
181+ private static RuntimeException ScriptCompilingException ( Exception e )
182+ {
183+ return new RuntimeException ( BilingualString . Localize (
184+ "Ошибка компиляции подключаемого сценария:\n " ,
185+ "Error compiling attached script:\n " ) + e . Message ) ;
186+ }
192187 }
193188}
0 commit comments