Code-Fight commented on code in PR #871:
URL:
https://github.com/apache/incubator-seata-go/pull/871#discussion_r2311816687
##########
.licenserc.yaml:
##########
@@ -80,7 +80,7 @@ header: # `header` section is configurations for source codes
license header.
- 'VERSION'
- ".errcheck-exclude"
- ".golangci.yml"
- - '.pre-commit-config.yaml'
+ - '.pre-commit-saga_config.yaml'
Review Comment:
Is this a mistaken modification?
##########
pkg/saga/statemachine/engine/config/default_statemachine_config.go:
##########
@@ -364,28 +359,27 @@ func (c *DefaultStateMachineConfig) LoadConfig(configPath
string) error {
return fmt.Errorf("failed to read config file: path=%s,
error=%w", configPath, err)
}
- parser := parser.NewStateMachineConfigParser()
- smo, err := parser.Parse(content)
- if err != nil {
- return fmt.Errorf("failed to parse state machine definition:
path=%s, error=%w", configPath, err)
- }
-
var configFileParams ConfigFileParams
- if err := json.Unmarshal(content, &configFileParams); err != nil {
+ ext := strings.ToLower(filepath.Ext(configPath))
+
+ switch ext {
+ case ".json":
+ if err := json.Unmarshal(content, &configFileParams); err !=
nil {
+ return fmt.Errorf("failed to unmarshal config file as
JSON: %w", err)
+ }
+ case ".yaml", ".yml":
if err := yaml.Unmarshal(content, &configFileParams); err !=
nil {
return fmt.Errorf("failed to unmarshal config file as
YAML: %w", err)
- } else {
- c.applyConfigFileParams(&configFileParams)
}
- } else {
- c.applyConfigFileParams(&configFileParams)
- }
-
- if _, exists := c.stateMachineDefs[smo.Name]; exists {
- return fmt.Errorf("state machine definition with name %s
already exists", smo.Name)
+ default:
+ if err := json.Unmarshal(content, &configFileParams); err !=
nil {
+ if err := yaml.Unmarshal(content, &configFileParams);
err != nil {
+ return fmt.Errorf("failed to unmarshal config
file (unknown type): %w", err)
+ }
Review Comment:
The logic here doesn’t make sense, because if the implementation supports
these two formats, it would never reach the Default case. Therefore, attempting
to parse unknown types as JSON or YAML is meaningless. It’s recommended to
simply indicate that the unknown type is not supported.
这里的的逻辑没有意义,因为若是这两种格式的实现,就不会走到Default中,所以这里尝试对未知类型进行json和yaml的解析,也就没有了意义。建议直接提示不支持的未知类型即可。
--
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]