Chromium Code Reviews| Index: runtime/bin/common.dart |
| diff --git a/runtime/bin/common.dart b/runtime/bin/common.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fab6033288dc6904ea9c2e2636ea29107dc936f5 |
| --- /dev/null |
| +++ b/runtime/bin/common.dart |
| @@ -0,0 +1,49 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +/** |
| + * Class for holding information on an error that was returned from the |
|
Mads Ager (google)
2012/03/13 10:56:17
An [OSError] object holds information about an err
Søren Gjesse
2012/03/13 12:39:49
Done.
|
| + * operating system. |
| + */ |
| +class OSError { |
| + static int noErrorCode = -1; |
|
Mads Ager (google)
2012/03/13 10:56:17
This should be final!
Søren Gjesse
2012/03/13 12:39:49
Absolutely, done.
|
| + |
| + const OSError([String this.message, int this.errorCode = -1]); |
|
Mads Ager (google)
2012/03/13 10:56:17
The -1 here should be noErrorCode?
Søren Gjesse
2012/03/13 12:39:49
Yes, now that noErrorCode is final it can.
|
| + |
| + String toString() { |
| + StringBuffer sb = new StringBuffer(); |
| + sb.add("OS Error"); |
| + if (message != null && message.length > 0) { |
|
Mads Ager (google)
2012/03/13 10:56:17
How about making this.message the empty string by
Søren Gjesse
2012/03/13 12:39:49
Done.
|
| + sb.add(": "); |
| + sb.add(message); |
| + if (errorCode != noErrorCode) { |
| + sb.add(", errno = "); |
| + sb.add(errorCode.toString()); |
| + } |
| + } else if (errorCode != noErrorCode) { |
| + sb.add(": errno = "); |
| + sb.add(errorCode.toString()); |
| + } |
| + return sb.toString(); |
| + } |
| + |
| + /** |
| + * Error message supplied by the operating system. null if no message is |
| + * associated with the error. |
| + */ |
| + final String message; |
| + |
| + /** |
| + * Error code supplied by the operating system. Will have the value |
| + * [noErrorCode] if there is no error code associated with the error. |
| + */ |
| + final int errorCode; |
| +} |
| + |
| + |
| +// TODO(sgjesse): Remove this once Dart constructors can be invoked |
|
Mads Ager (google)
2012/03/13 10:56:17
Please make this an actual doc comment where it sa
Søren Gjesse
2012/03/13 12:39:49
Done.
|
| +// through the API. |
| +class IOUtils { |
| + static OSError makeOSError(message, code) => new OSError(message, code); |
| +} |