diff --git a/glslc/src/dependency_info.cc b/glslc/src/dependency_info.cc index 2f1ef2f4a..1ba3afb9c 100644 --- a/glslc/src/dependency_info.cc +++ b/glslc/src/dependency_info.cc @@ -50,6 +50,10 @@ bool DependencyInfoDumpingHandler::DumpDependencyInfo( std::ofstream potential_file_stream_for_dep_info_dump; std::ostream* dep_file_stream = shaderc_util::GetOutputStream( dep_file_name, &potential_file_stream_for_dep_info_dump, &std::cerr); + if (!dep_file_stream) { + // An error message has already been emitted to the stderr stream. + return false; + } *dep_file_stream << dep_string_stream.str(); if (dep_file_stream->fail()) { std::cerr << "glslc: error: error writing dependent_files info to output " diff --git a/glslc/test/option_dash_M.py b/glslc/test/option_dash_M.py index e32ff0720..39091c0d4 100644 --- a/glslc/test/option_dash_M.py +++ b/glslc/test/option_dash_M.py @@ -752,3 +752,13 @@ class TestErrorMissingDependencyTargetName(expect.StderrMatch): glslc_args = ['target', 'shader.vert', '-c', '-MT'] expected_stderr = ['glslc: error: ' 'missing dependency info target after \'-MT\'\n'] + + +@inside_glslc_testsuite('OptionsCapM') +class TestErrorDashMFUnwritableFile(expect.ErrorMessageSubstr): + """Tests that when we fail to make an output dependency file, glslc + fails gracefully and emits an error message instead of crashing.""" + environment = EMPTY_SHADER_IN_CURDIR + bad_file = '/file/should/not/exist/today.d' + glslc_args = ['-MD', '-MF', bad_file, 'shader.vert'] + expected_error_substr = ['cannot open output file']