gnodet-bot commented on code in PR #26620: URL: https://github.com/apache/camel/pull/26620#discussion_r4056547071
########## dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/StructureChecks.java: ########## @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.dsl.jbang.core.commands.ai; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Checks on the order of the top-level entries of a YAML route file. The schema accepts the entries in any order; the + * runtime does not: an onException, onCompletion or intercept written after a route fails at startup with "onException + * must be defined before any routes in the RouteBuilder", a Java DSL sentence for a YAML author (CAMEL-24846). The + * check names the line, the entry, and where it goes. + */ +public final class StructureChecks { + + /** A top-level list item: "- route:", "- onException:" (indent 0). */ + private static final Pattern TOP_LEVEL_ENTRY = Pattern.compile("^- ([A-Za-z][A-Za-z0-9]*)\\s*:"); + + /** The entries the runtime requires before the first route. */ + private static final Set<String> BEFORE_ROUTES + = Set.of("onException", "onCompletion", "intercept", "interceptFrom", "interceptSendToEndpoint"); Review Comment: ⚠️ **`errorHandler` is missing from `BEFORE_ROUTES`.** The `YamlRoutesBuilderLoader` (line 245) enforces the same constraint for `errorHandler` — writing `- errorHandler:` after a route throws `"errorHandler must be defined before any routes in the RouteBuilder"` at startup, but this set won't detect it. ```suggestion private static final Set<String> BEFORE_ROUTES = Set.of("onException", "onCompletion", "intercept", "interceptFrom", "interceptSendToEndpoint", "errorHandler"); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
