mbeckerle commented on code in PR #1170: URL: https://github.com/apache/daffodil/pull/1170#discussion_r1507950582
########## daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/layers/api/LayerRuntime.java: ########## @@ -0,0 +1,57 @@ +/* + * 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.daffodil.runtime1.layers.api; + +import java.nio.charset.Charset; + +/** + * Runtime information and stateful services available to the layer when + * encoding/decoding the layer data to/from the input/output stream. + * + * Provides the ability to cause runtime processing errors, which can cause backtracking + * when parsing, but are fatal when unparsing. + * + * Also provides the ability to cause runtime schema definition errors, which are always + * fatal. + * + * This object contains the processor state, but hidden behind an API so that only relevant + * aspects of the processor state are visible. + */ +public interface LayerRuntime extends LayerCompileInfo { + + Charset getCharset(String layerEncoding); + + void processingError(String msg); + + void processingError(Throwable cause); + + void runtimeSchemaDefinitionError(String msg, Object... args); + + void runtimeSchemaDefinitionError(Throwable cause); + + String getString(LayerVariable variable); + + void setString(LayerVariable variable, String s); + + int getInt(LayerVariable variable); + + void setInt(LayerVariable variable, int v); + + long getLong(LayerVariable variable); + + void setLong(LayerVariable variable, long v); +} Review Comment: Yes, the primary purpose of the LayerRuntime object is to be the context object of that use of the layer so that thrown exceptions get associated with that context and diagnostics messaging can point at that layer use point in the schema. The problem is that the API being called is just InputStream.read or OutputStream.write, and I don't want to add a proxy and try-catch on every such call just so that if an error occurs we can associate that thrown exception with the daffodil layer context. For parsing we could avoid this as it proceeds in an orderly traversal, so the LayerParser can have the catches. For unparsing.... the unordered nature of unparsing mean that the LayerUnparser is long gone from the stack by the time the layer is potentially being written to and closed, which is at the time suspensions are finally being completed allowing the blocked unparsing that writes to them to finish. This could be in some context where I'm not sure what exactly would be catching the exceptions. This needs more thought. -- 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]
