-
Notifications
You must be signed in to change notification settings - Fork 25
Добавлена обработка ошибки чтения содержимого прав роли #564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| package com.github._1c_syntax.bsl.reader.designer.converter; | ||
|
|
||
| import com.github._1c_syntax.bsl.mdo.Role; | ||
| import com.github._1c_syntax.bsl.mdo.storage.RoleData; | ||
| import com.github._1c_syntax.bsl.reader.common.converter.AbstractReadConverter; | ||
| import com.github._1c_syntax.bsl.reader.common.xstream.ExtendXStream; | ||
| import com.thoughtworks.xstream.converters.UnmarshallingContext; | ||
|
|
@@ -38,8 +39,15 @@ public class RoleConverter extends AbstractReadConverter { | |
| @Override | ||
| public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { | ||
| var readerContext = super.read(reader, context); | ||
| readerContext.setValue(DATA_FIELD, | ||
| ExtendXStream.read(reader, dataPath(readerContext.getCurrentPath(), readerContext.getName()))); | ||
| RoleData data; | ||
| try { | ||
| data = (RoleData) ExtendXStream.read(reader, dataPath(readerContext.getCurrentPath(), readerContext.getName())); | ||
| } catch (Exception e) { | ||
| // ничего не делаем, считаем файл битым | ||
| data = RoleData.EMPTY; | ||
| } | ||
|
|
||
| readerContext.setValue(DATA_FIELD, data); | ||
|
Comment on lines
+42
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# First, find the RoleData class definition
find . -type f -name "*.java" | xargs grep -l "class RoleData" | head -5Repository: 1c-syntax/mdclasses Length of output: 223 🏁 Script executed: #!/bin/bash
# Search for RoleData.EMPTY usage
rg "RoleData\.EMPTY" -A 3 -B 3Repository: 1c-syntax/mdclasses Length of output: 5143 🏁 Script executed: #!/bin/bash
# Find the RoleData class file
find . -type f -name "RoleData.java"Repository: 1c-syntax/mdclasses Length of output: 130 🏁 Script executed: #!/bin/bash
# Examine the RoleData class definition
cat -n src/main/java/com/github/_1c_syntax/bsl/mdo/storage/RoleData.javaRepository: 1c-syntax/mdclasses Length of output: 2638 🏁 Script executed: #!/bin/bash
# Check the RoleConverter file to see if there's any logging
cat -n src/main/java/com/github/_1c_syntax/bsl/reader/designer/converter/RoleConverter.java | head -100Repository: 1c-syntax/mdclasses Length of output: 2702 Add logging for silently caught role data loading failures.
However, the silent exception handling lacks any logging or alerting mechanism. When role configuration fails to load, administrators have no visibility into the failure, only a comment stating the file is "considered corrupted." For security-sensitive code, silent failures should be logged to inform operators that role configurations could not be loaded. 🤖 Prompt for AI Agents |
||
| return readerContext.build(); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| package com.github._1c_syntax.bsl.reader.edt.converter; | ||
|
|
||
| import com.github._1c_syntax.bsl.mdo.Role; | ||
| import com.github._1c_syntax.bsl.mdo.storage.RoleData; | ||
| import com.github._1c_syntax.bsl.reader.common.converter.AbstractReadConverter; | ||
| import com.github._1c_syntax.bsl.reader.common.xstream.ExtendXStream; | ||
| import com.thoughtworks.xstream.converters.UnmarshallingContext; | ||
|
|
@@ -37,7 +38,15 @@ public class RoleConverter extends AbstractReadConverter { | |
| @Override | ||
| public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { | ||
| var readerContext = super.read(reader, context); | ||
| readerContext.setValue(DATA_FIELD, ExtendXStream.read(reader, dataPath(readerContext.getCurrentPath()))); | ||
| RoleData data; | ||
| try { | ||
| data = (RoleData) ExtendXStream.read(reader, dataPath(readerContext.getCurrentPath())); | ||
| } catch (Exception e) { | ||
| // ничего не делаем, считаем файл битым | ||
| data = RoleData.EMPTY; | ||
| } | ||
|
Comment on lines
+42
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add logging and narrow the exception type. Same concern as in the designer converter: catching all exceptions silently creates observability gaps and could hide unexpected errors beyond the Consider logging at WARN/ERROR level and narrowing to 📋 Suggested improvement+import com.thoughtworks.xstream.converters.ConversionException;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
@EDTConverter
public class RoleConverter extends AbstractReadConverter {
// ...
RoleData data;
try {
data = (RoleData) ExtendXStream.read(reader, dataPath(readerContext.getCurrentPath()));
- } catch (Exception e) {
- // ничего не делаем, считаем файл битым
+ } catch (ConversionException e) {
+ var rightsPath = dataPath(readerContext.getCurrentPath());
+ log.warn("Can't read role rights file '{}' - it's broken (skipped)", rightsPath, e);
data = RoleData.EMPTY;
}
🤖 Prompt for AI Agents |
||
|
|
||
| readerContext.setValue(DATA_FIELD, data); | ||
| return readerContext.build(); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add logging and narrow the exception type.
The current implementation catches all exceptions silently, which creates observability and debugging challenges:
Exceptionwill swallow unexpected errors beyond theConversionExceptionmentioned in issue ConversionException: #563 (e.g.,IOException,NullPointerExceptionfrom other causes).Consider logging the error at WARN or ERROR level and narrowing the catch to expected exception types.
📋 Suggested improvement