1

Resolved

Error handling in msbuild task

description

I am confused with a behaviour of msbuild task (both js and css). It produces an error log on js or css parsing error, but the task itself does not fail (i.e. return code is true). I've made a little research, and here it is...

Class JavaScriptCompressorTask
public override bool Execute()
        {
            try
            {
                return base.Execute();
            }
            catch (EcmaScriptException ecmaScriptException)
            {
                Log.LogError("An error occurred in parsing the Javascript file.");
                if (ecmaScriptException.LineNumber == -1)
                {
                    Log.LogError("[ERROR] {0} ********", ecmaScriptException.Message);
                }
                else
                {
                    Log.LogError(
                        "[ERROR] {0} ******** Line: {2}. LineOffset: {3}. LineSource: \"{4}\"",
                        ecmaScriptException.Message,
                        string.IsNullOrEmpty(ecmaScriptException.SourceName)
                            ? string.Empty
                            : "Source: {1}. " + ecmaScriptException.SourceName,
                        ecmaScriptException.LineNumber,
                        ecmaScriptException.ColumnNumber,
                        ecmaScriptException.LineSource);
                }
                return false;
            }
        }
it excepts EcmaScriptException and contains logic to handle it, BUT the class CompressorTaskEngine that is called inside base.Execute(); contains the following exceptions handler:
catch (Exception exception)
                    {
                        if (exception is FileNotFoundException)
                        {
                            Log.LogError(string.Format(CultureInfo.InvariantCulture, "ERROR reading file or path [{0}].", file.FileName));
                        }
                        else
                        {
                            // FFS :( Something bad happened.
                            Log.LogError(string.Format(CultureInfo.InvariantCulture, "Failed to read/parse data in file [{0}].", file.FileName));
                        }
                        Log.LogErrorFromException(exception, false);
                    }
So, as we can see, the exception is logged, but doesn't cause false return code. It seems like an error to me. Am i missing something?

comments

freeranger wrote Aug 8, 2014 at 7:11 PM

Hi,

Good spot. There are a lot of other checks prior to this point, which return false when they log an exception, but not for this situation. We will amend this for the next release. Thanks for pointing it out.

freeranger wrote Aug 19, 2014 at 9:07 AM

Fixed in the latest source, which is now on github:
https://github.com/PureKrome/YUICompressor.NET

wrote Aug 19, 2014 at 9:08 AM