bito-code-review[bot] commented on code in PR #43827:
URL: https://github.com/apache/superset/pull/43827#discussion_r4044485074


##########
superset/commands/semantic_layer/utils.py:
##########
@@ -0,0 +1,48 @@
+# 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.
+"""Shared validation for semantic layer configuration commands."""
+
+from __future__ import annotations
+
+from typing import Any
+
+from pydantic import ValidationError
+from superset_core.semantic_layers.layer import SemanticLayer
+
+from superset.commands.semantic_layer.exceptions import 
SemanticLayerInvalidError
+
+
+def validate_configuration(
+    layer_class: type[SemanticLayer[Any, Any]], configuration: dict[str, Any]
+) -> None:
+    """Validate provider configuration without exposing values in error 
traces."""
+    try:
+        layer_class.from_configuration(configuration)
+    except ValidationError as ex:
+        # Messages and context can contain credentials even when input is 
omitted.
+        # Retain only structural paths and error codes, never the original 
cause.
+        details: str = "; ".join(
+            f"{'.'.join(map(str, error['loc'])) or '<root>'}: {error['type']}"
+            for error in ex.errors(
+                include_input=False, include_url=False, include_context=False
+            )
+        )
+        raise SemanticLayerInvalidError(f"Invalid configuration: {details}") 
from None
+    except Exception:  # pylint: disable=broad-except
+        # A provider may interpolate the restored credential into a
+        # non-pydantic error; never let one reach an exc_info log sink.
+        raise SemanticLayerInvalidError("Provider rejected the configuration") 
from None

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Swallowed provider diagnostics</b></div>
   <div id="fix">
   
   The broad `except Exception` around `layer_class.from_configuration` drops 
every diagnostic: a provider bug (AttributeError, KeyError) surfaces to users 
as a 422 "Provider rejected the configuration" with no server-side trace, and 
`from None` suppresses the cause. Logging only `type(exc).__name__` and 
`layer_class.__name__` keeps messages/args out of logs while restoring 
diagnosability.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #2dfe2a</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to