DescriptorValidationException.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc.
  3. // http://code.google.com/p/protobuf/
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. using System;
  17. namespace Google.ProtocolBuffers.Descriptors {
  18. /// <summary>
  19. /// Thrown when building descriptors fails because the source DescriptorProtos
  20. /// are not valid.
  21. /// </summary>
  22. public sealed class DescriptorValidationException : Exception {
  23. private readonly String name;
  24. private readonly IMessage proto;
  25. private readonly string description;
  26. /// <value>
  27. /// The full name of the descriptor where the error occurred.
  28. /// </value>
  29. public String ProblemSymbolName {
  30. get { return name; }
  31. }
  32. /// <value>
  33. /// The protocol message representation of the invalid descriptor.
  34. /// </value>
  35. public IMessage ProblemProto {
  36. get { return proto; }
  37. }
  38. /// <value>
  39. /// A human-readable description of the error. (The Message property
  40. /// is made up of the descriptor's name and this description.)
  41. /// </value>
  42. public string Description {
  43. get { return description; }
  44. }
  45. internal DescriptorValidationException(IDescriptor problemDescriptor, string description) :
  46. base(problemDescriptor.FullName + ": " + description) {
  47. // Note that problemDescriptor may be partially uninitialized, so we
  48. // don't want to expose it directly to the user. So, we only provide
  49. // the name and the original proto.
  50. name = problemDescriptor.FullName;
  51. proto = problemDescriptor.Proto;
  52. this.description = description;
  53. }
  54. internal DescriptorValidationException(IDescriptor problemDescriptor, string description, Exception cause) :
  55. base(problemDescriptor.FullName + ": " + description, cause) {
  56. name = problemDescriptor.FullName;
  57. proto = problemDescriptor.Proto;
  58. this.description = description;
  59. }
  60. }
  61. }