| 63 | } |
| 64 | |
| 65 | Status AllowedStringValue(const string& str, const OpDef::AttrDef& attr) { |
| 66 | const AttrValue& allowed_values(attr.allowed_values()); |
| 67 | for (const auto& allowed : allowed_values.list().s()) { |
| 68 | if (str == allowed) { |
| 69 | return Status::OK(); |
| 70 | } |
| 71 | } |
| 72 | string allowed_str; |
| 73 | for (const string& allowed : allowed_values.list().s()) { |
| 74 | if (!allowed_str.empty()) { |
| 75 | strings::StrAppend(&allowed_str, ", "); |
| 76 | } |
| 77 | strings::StrAppend(&allowed_str, "\"", allowed, "\""); |
| 78 | } |
| 79 | return errors::InvalidArgument( |
| 80 | "Value for attr '", attr.name(), "' of \"", str, |
| 81 | "\" is not in the list of allowed values: ", allowed_str); |
| 82 | } |
| 83 | |
| 84 | } // namespace |
| 85 |
no test coverage detected