|
| 1 | +// Copyright 2026 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package dev.cel.common.exceptions; |
| 16 | + |
| 17 | +import dev.cel.common.CelErrorCode; |
| 18 | +import dev.cel.common.CelRuntimeException; |
| 19 | +import dev.cel.common.annotations.Internal; |
| 20 | +import java.util.Collection; |
| 21 | +import java.util.Collections; |
| 22 | + |
| 23 | +/** Indicates that a matching overload could not be found during function dispatch. */ |
| 24 | +@Internal |
| 25 | +public final class CelOverloadNotFoundException extends CelRuntimeException { |
| 26 | + |
| 27 | + public CelOverloadNotFoundException(String functionName) { |
| 28 | + this(functionName, Collections.emptyList()); |
| 29 | + } |
| 30 | + |
| 31 | + public CelOverloadNotFoundException(String functionName, Collection<String> overloadIds) { |
| 32 | + super(formatErrorMessage(functionName, overloadIds), CelErrorCode.OVERLOAD_NOT_FOUND); |
| 33 | + } |
| 34 | + |
| 35 | + private static String formatErrorMessage(String functionName, Collection<String> overloadIds) { |
| 36 | + StringBuilder sb = new StringBuilder(); |
| 37 | + sb.append("No matching overload for function '").append(functionName).append("'."); |
| 38 | + if (!overloadIds.isEmpty()) { |
| 39 | + sb.append(" Overload candidates: ").append(String.join(", ", overloadIds)); |
| 40 | + } |
| 41 | + |
| 42 | + return sb.toString(); |
| 43 | + } |
| 44 | +} |
0 commit comments