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

Side by Side Diff: mojo/public/cpp/bindings/lib/validation_errors.cc

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
6
7 #include <string>
8
9 #include "mojo/public/cpp/environment/logging.h"
10
11 namespace mojo {
12 namespace internal {
13 namespace {
14
15 ValidationErrorObserverForTesting* g_validation_error_observer = nullptr;
16
17 } // namespace
18
19 // TODO(vardhan): There are golden files
20 // (mojo/public/interfaces/bindings/tests/data/validation/*expected) with these
21 // strings shared between languages, so changing them here requires changing
22 // them in all languages, along with the golden files.
23 const char* ValidationErrorToString(ValidationError error) {
24 switch (error) {
25 case ValidationError::NONE:
26 return "VALIDATION_ERROR_NONE";
27 case ValidationError::MISALIGNED_OBJECT:
28 return "VALIDATION_ERROR_MISALIGNED_OBJECT";
29 case ValidationError::ILLEGAL_MEMORY_RANGE:
30 return "VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE";
31 case ValidationError::UNEXPECTED_STRUCT_HEADER:
32 return "VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER";
33 case ValidationError::UNEXPECTED_ARRAY_HEADER:
34 return "VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER";
35 case ValidationError::ILLEGAL_HANDLE:
36 return "VALIDATION_ERROR_ILLEGAL_HANDLE";
37 case ValidationError::UNEXPECTED_INVALID_HANDLE:
38 return "VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE";
39 case ValidationError::ILLEGAL_POINTER:
40 return "VALIDATION_ERROR_ILLEGAL_POINTER";
41 case ValidationError::UNEXPECTED_NULL_POINTER:
42 return "VALIDATION_ERROR_UNEXPECTED_NULL_POINTER";
43 case ValidationError::MESSAGE_HEADER_INVALID_FLAGS:
44 return "VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAGS";
45 case ValidationError::MESSAGE_HEADER_MISSING_REQUEST_ID:
46 return "VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID";
47 case ValidationError::MESSAGE_HEADER_UNKNOWN_METHOD:
48 return "VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD";
49 case ValidationError::DIFFERENT_SIZED_ARRAYS_IN_MAP:
50 return "VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP";
51 case ValidationError::UNEXPECTED_NULL_UNION:
52 return "VALIDATION_ERROR_UNEXPECTED_NULL_UNION";
53 }
54
55 return "Unknown error";
56 }
57
58 void ReportValidationError(ValidationError error, std::string* description) {
59 if (g_validation_error_observer) {
60 g_validation_error_observer->set_last_error(error);
61 } else if (description) {
62 MOJO_LOG(ERROR) << "Invalid message: " << ValidationErrorToString(error)
63 << " (" << *description << ")";
64 } else {
65 MOJO_LOG(ERROR) << "Invalid message: " << ValidationErrorToString(error);
66 }
67 }
68
69 ValidationErrorObserverForTesting::ValidationErrorObserverForTesting()
70 : last_error_(ValidationError::NONE) {
71 MOJO_DCHECK(!g_validation_error_observer);
72 g_validation_error_observer = this;
73 }
74
75 ValidationErrorObserverForTesting::~ValidationErrorObserverForTesting() {
76 MOJO_DCHECK(g_validation_error_observer == this);
77 g_validation_error_observer = nullptr;
78 }
79
80 ValidationErrorStringStream::ValidationErrorStringStream(std::string* err_msg)
81 : err_msg_(err_msg) {}
82
83 ValidationErrorStringStream::~ValidationErrorStringStream() {
84 if (err_msg_)
85 *err_msg_ = stream_.str();
86 }
87
88 } // namespace internal
89 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_errors.h ('k') | mojo/public/cpp/bindings/lib/validation_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698