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

Side by Side 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, 4 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 unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | test/io_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart_style.src.formatter_options; 5 library dart_style.src.formatter_options;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'source_code.dart'; 10 import 'source_code.dart';
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 "length": output.selectionLength != null ? output.selectionLength : -1 109 "length": output.selectionLength != null ? output.selectionLength : -1
110 } 110 }
111 })); 111 }));
112 } 112 }
113 } 113 }
114 114
115 /// Overwrites each file with its formatted result. 115 /// Overwrites each file with its formatted result.
116 class _OverwriteReporter extends _PrintReporter { 116 class _OverwriteReporter extends _PrintReporter {
117 void afterFile(File file, String label, SourceCode output, {bool changed}) { 117 void afterFile(File file, String label, SourceCode output, {bool changed}) {
118 if (changed) { 118 if (changed) {
119 file.writeAsStringSync(output.text); 119 try {
120 print("Formatted $label"); 120 file.writeAsStringSync(output.text);
121 print("Formatted $label");
122 } on FileSystemException catch (err) {
123 stderr.writeln("Could not overwrite $label: "
124 "${err.osError.message} (error code ${err.osError.errorCode})");
125 }
121 } else { 126 } else {
122 print("Unchanged $label"); 127 print("Unchanged $label");
123 } 128 }
124 } 129 }
125 } 130 }
126 131
127 /// A decorating reporter that reports how long it took for format each file. 132 /// A decorating reporter that reports how long it took for format each file.
128 class ProfileReporter implements OutputReporter { 133 class ProfileReporter implements OutputReporter {
129 final OutputReporter _inner; 134 final OutputReporter _inner;
130 135
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 var elapsed = new DateTime.now().difference(_ongoing.remove(label)); 195 var elapsed = new DateTime.now().difference(_ongoing.remove(label));
191 if (elapsed.inMilliseconds >= 10) { 196 if (elapsed.inMilliseconds >= 10) {
192 _elapsed[label] = elapsed; 197 _elapsed[label] = elapsed;
193 } else { 198 } else {
194 _elided++; 199 _elided++;
195 } 200 }
196 201
197 _inner.afterFile(file, label, output, changed: changed); 202 _inner.afterFile(file, label, output, changed: changed);
198 } 203 }
199 } 204 }
OLDNEW
« 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