diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index 7818e4dc5..715cff6ba 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Composition; using System.IO; @@ -39,16 +39,23 @@ protected override async Task OnFileFound(ProcessRequest processRequest, IDictio var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder; var file = processRequest.ComponentStream; var filePath = file.Location; - this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); + try + { + this.Logger.LogInfo($"Discovered dockerfile: {file.Location}"); - string contents; - using (var reader = new StreamReader(file.Stream)) + string contents; + using (var reader = new StreamReader(file.Stream)) + { + contents = await reader.ReadToEndAsync(); + } + + var stageNameMap = new Dictionary(); + var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); + } catch (Exception e) { - contents = await reader.ReadToEndAsync(); + this.Logger.LogError($"The file doesn't appear to be a Dockerfile: '{file.Location}'"); + this.Logger.LogException(e, false); } - - var stageNameMap = new Dictionary(); - var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap); } private Task ParseDockerFile(string fileContents, string fileLocation, ISingleFileComponentRecorder singleFileComponentRecorder, Dictionary stageNameMap)