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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 8492015: Allow printf-style arguments for Dart_Error and Api::Error. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 1 month 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
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 1265)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -67,8 +67,12 @@
}
-DART_EXPORT Dart_Handle Dart_Error(const char* error) {
- return Api::Error(error);
+DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ Dart_Handle error = Api::VError(format, args);
+ va_end(args);
+ return error;
}
@@ -527,7 +531,9 @@
cls_name ^= param.raw();
const Class& cls = Class::Handle(lib.LookupClass(cls_name));
if (cls.IsNull()) {
- return Api::Error("Specified class does not exist");
+ const String& lib_name = String::Handle(lib.name());
+ return Api::Error("Class '%s' not found in library '%s'.",
+ cls_name.ToCString(), lib_name.ToCString());
}
return Api::NewLocalHandle(cls);
}
@@ -2008,15 +2014,29 @@
}
-Dart_Handle Api::Error(const char* text) {
+Dart_Handle Api::VError(const char* format, va_list args) {
Zone zone; // Setup a VM zone as we are creating some handles.
HandleScope scope; // Setup a VM handle scope.
- const String& message = String::Handle(String::New(text));
+
+ // We currently truncate error messages at 1024 chars.
+ char* buffer = reinterpret_cast<char*>(zone.Allocate(1024));
+ OS::VSNPrint(buffer, 1024, format, args);
siva 2011/11/07 23:20:50 Normally we have used this style to avoid having t
turnidge 2011/11/07 23:55:35 Done.
+
+ const String& message = String::Handle(String::New(buffer));
const Object& obj = Object::Handle(ApiFailure::New(message));
return Api::NewLocalHandle(obj);
}
+Dart_Handle Api::Error(const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ Dart_Handle error = Api::VError(format, args);
+ va_end(args);
+ return error;
+}
+
+
Dart_Handle Api::Null() {
Isolate* isolate = Isolate::Current();
ASSERT(isolate != NULL);

Powered by Google App Engine
This is Rietveld 408576698