@@ -183,6 +183,7 @@ private void Initialize(
183183 this . includeRegexList = new List < Regex > ( ) ;
184184 this . excludeRegexList = new List < Regex > ( ) ;
185185
186+ #region ParseProfile
186187 if ( ! String . IsNullOrWhiteSpace ( profile ) )
187188 {
188189 try
@@ -191,9 +192,7 @@ private void Initialize(
191192 }
192193 catch
193194 {
194- this . outputWriter . WriteError ( new ErrorRecord ( new FileNotFoundException ( ) ,
195- string . Format ( CultureInfo . CurrentCulture , Strings . FileNotFound , profile ) ,
196- ErrorCategory . InvalidArgument , this ) ) ;
195+ this . outputWriter . WriteWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . FileNotFound , profile ) ) ;
197196 }
198197
199198 if ( File . Exists ( profile ) )
@@ -202,15 +201,23 @@ private void Initialize(
202201 ParseError [ ] parserErrors = null ;
203202 Ast profileAst = Parser . ParseFile ( profile , out parserTokens , out parserErrors ) ;
204203 IEnumerable < Ast > hashTableAsts = profileAst . FindAll ( item => item is HashtableAst , false ) ;
205- foreach ( HashtableAst hashTableAst in hashTableAsts )
204+
205+ // no hashtable, raise warning
206+ if ( hashTableAsts . Count ( ) == 0 )
207+ {
208+ this . outputWriter . WriteWarning ( string . Format ( CultureInfo . CurrentCulture , Strings . InvalidProfile , profile ) ) ;
209+ }
210+ else
206211 {
212+ HashtableAst hashTableAst = hashTableAsts . First ( ) as HashtableAst ;
213+
207214 foreach ( var kvp in hashTableAst . KeyValuePairs )
208215 {
209216 if ( ! ( kvp . Item1 is StringConstantExpressionAst ) )
210217 {
211- this . outputWriter . WriteError ( new ErrorRecord ( new ArgumentException ( ) ,
212- string . Format ( CultureInfo . CurrentCulture , Strings . WrongKeyFormat , kvp . Item1 . Extent . StartLineNumber , kvp . Item1 . Extent . StartColumnNumber , profile ) ,
213- ErrorCategory . InvalidArgument , this ) ) ;
218+ // first item (the key) should be a string
219+ this . outputWriter . WriteWarning (
220+ string . Format ( CultureInfo . CurrentCulture , Strings . WrongKeyFormat , kvp . Item1 . Extent . StartLineNumber , kvp . Item1 . Extent . StartColumnNumber , profile ) ) ;
214221 continue ;
215222 }
216223
@@ -257,11 +264,11 @@ private void Initialize(
257264 {
258265 foreach ( var element in arrayLitAst . Elements )
259266 {
267+ // all the values in the array needs to be string
260268 if ( ! ( element is StringConstantExpressionAst ) )
261269 {
262- this . outputWriter . WriteError ( new ErrorRecord ( new ArgumentException ( ) ,
263- string . Format ( CultureInfo . CurrentCulture , Strings . WrongValueFormat , element . Extent . StartLineNumber , element . Extent . StartColumnNumber , profile ) ,
264- ErrorCategory . InvalidArgument , this ) ) ;
270+ this . outputWriter . WriteWarning (
271+ string . Format ( CultureInfo . CurrentCulture , Strings . WrongValueFormat , element . Extent . StartLineNumber , element . Extent . StartColumnNumber , profile ) ) ;
265272 continue ;
266273 }
267274
@@ -273,9 +280,8 @@ private void Initialize(
273280
274281 if ( rhsList . Count == 0 )
275282 {
276- this . outputWriter . WriteError ( new ErrorRecord ( new ArgumentException ( ) ,
277- string . Format ( CultureInfo . CurrentCulture , Strings . WrongValueFormat , kvp . Item2 . Extent . StartLineNumber , kvp . Item2 . Extent . StartColumnNumber , profile ) ,
278- ErrorCategory . InvalidArgument , this ) ) ;
283+ this . outputWriter . WriteWarning (
284+ string . Format ( CultureInfo . CurrentCulture , Strings . WrongValueFormat , kvp . Item2 . Extent . StartLineNumber , kvp . Item2 . Extent . StartColumnNumber , profile ) ) ;
279285 break ;
280286 }
281287
@@ -312,16 +318,17 @@ private void Initialize(
312318 }
313319 break ;
314320 default :
315- this . outputWriter . WriteError ( new ErrorRecord ( new ArgumentException ( ) ,
316- string . Format ( CultureInfo . CurrentCulture , Strings . WrongKey , kvp . Item1 . Extent . StartLineNumber , kvp . Item1 . Extent . StartColumnNumber , profile ) ,
317- ErrorCategory . InvalidArgument , this ) ) ;
321+ this . outputWriter . WriteWarning (
322+ string . Format ( CultureInfo . CurrentCulture , Strings . WrongKey , kvp . Item1 . Extent . StartLineNumber , kvp . Item1 . Extent . StartColumnNumber , profile ) ) ;
318323 break ;
319324 }
320325 }
321326 }
322327 }
323328 }
324329
330+ #endregion
331+
325332 //Check wild card input for the Include/ExcludeRules and create regex match patterns
326333 if ( this . includeRule != null )
327334 {
0 commit comments