Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Unified Diff: lib/src/formatter_options.dart

Issue 2192883003: Gracefully handle IO errors when failing to overwrite a file. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | test/io_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/formatter_options.dart
diff --git a/lib/src/formatter_options.dart b/lib/src/formatter_options.dart
index 248941fb9ae088a2e19af01d14687217e6a2aa06..6195d189ad7f294afbe8b1d8ff7894e965cf6861 100644
--- a/lib/src/formatter_options.dart
+++ b/lib/src/formatter_options.dart
@@ -116,8 +116,13 @@ class _PrintJsonReporter extends OutputReporter {
class _OverwriteReporter extends _PrintReporter {
void afterFile(File file, String label, SourceCode output, {bool changed}) {
if (changed) {
- file.writeAsStringSync(output.text);
- print("Formatted $label");
+ try {
+ file.writeAsStringSync(output.text);
+ print("Formatted $label");
+ } on FileSystemException catch (err) {
+ stderr.writeln("Could not overwrite $label: "
+ "${err.osError.message} (error code ${err.osError.errorCode})");
+ }
} else {
print("Unchanged $label");
}
« no previous file with comments | « CHANGELOG.md ('k') | test/io_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698