Skip to content

Commit 9f60fc6

Browse files
committed
Fix error logging
1 parent 55333e4 commit 9f60fc6

File tree

6 files changed

+44
-15
lines changed

6 files changed

+44
-15
lines changed

app/grpc/data_type_handler.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
class DataTypeHandler < Tucana::Sagittarius::DataTypeService::Service
44
include GrpcHandler
5-
include Code0::ZeroTrack::Loggable
65

76
def update(request, _call)
87
current_runtime = Runtime.find(Code0::ZeroTrack::Context.current[:runtime][:id])
98

109
response = Runtimes::DataTypes::UpdateService.new(current_runtime, request.data_types).execute
1110

12-
logger.info(message: 'Data types updated', runtime_id: current_runtime.id, response: response.to_h)
13-
1411
Tucana::Sagittarius::DataTypeUpdateResponse.new(success: response.success?)
1512
end
1613
end

app/services/error_code.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def self.error_codes
8080
no_datatype_identifier_for_generic_key: { description: 'No data type identifier could be found for the given generic key' },
8181
invalid_generic_mapper: { description: 'The generic mapper is invalid because of active model errors' },
8282
invalid_data_type: { description: 'The data type is invalid because of active model errors' },
83+
invalid_flow_type: { description: 'The flow type is invalid because of active model errors' },
8384

8485
primary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },
8586
secondary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },

app/services/runtimes/data_types/update_service.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Runtimes
44
module DataTypes
55
class UpdateService
66
include Sagittarius::Database::Transactional
7+
include Code0::ZeroTrack::Loggable
78

89
attr_reader :current_runtime, :data_types
910

@@ -18,14 +19,22 @@ def execute
1819
DataType.where(runtime: current_runtime).update_all(removed_at: Time.zone.now)
1920
# rubocop:enable Rails/SkipsModelValidations
2021
sort_data_types(data_types).each do |data_type|
21-
unless update_datatype(data_type, t)
22-
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update data type',
23-
error_code: :invalid_data_type, details: data_type.errors)
24-
end
22+
db_data_type = update_datatype(data_type, t)
23+
next if db_data_type.persisted?
24+
25+
logger.error(message: 'Failed to update data type',
26+
runtime_id: current_runtime.id,
27+
data_type_identifier: data_type.identifier,
28+
errors: db_data_type.errors.full_messages)
29+
30+
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update data type',
31+
error_code: :invalid_data_type, details: db_data_type.errors)
2532
end
2633

2734
UpdateRuntimeCompatibilityJob.perform_later({ runtime_id: current_runtime.id })
2835

36+
logger.info(message: 'Updated data types for runtime', runtime_id: current_runtime.id)
37+
2938
ServiceResponse.success(message: 'Updated data types', payload: data_types)
3039
end
3140
end
@@ -80,6 +89,7 @@ def update_datatype(data_type, t)
8089
db_object.generic_keys = data_type.generic_keys.to_a
8190
db_object.version = "#{data_type.version.major}.#{data_type.version.minor}.#{data_type.version.patch}"
8291
db_object.save
92+
db_object
8393
end
8494

8595
def find_data_type_identifier(parent_type_rule_config, t)

app/services/runtimes/flow_types/update_service.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Runtimes
44
module FlowTypes
55
class UpdateService
66
include Sagittarius::Database::Transactional
7+
include Code0::ZeroTrack::Loggable
78

89
attr_reader :current_runtime, :flow_types
910

@@ -18,10 +19,19 @@ def execute
1819
FlowType.where(runtime: current_runtime).update_all(removed_at: Time.zone.now)
1920
# rubocop:enable Rails/SkipsModelValidations
2021
flow_types.each do |flow_type|
21-
unless update_flowtype(flow_type, t)
22-
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update flow type',
23-
payload: flow_type.errors)
24-
end
22+
db_flow_type = update_flowtype(flow_type, t)
23+
next if db_flow_type.persisted?
24+
25+
logger.error(
26+
message: 'Failed to update flow type',
27+
runtime_id: current_runtime.id,
28+
flow_type_identifier: flow_type.identifier,
29+
errors: db_flow_type.errors.full_messages
30+
)
31+
32+
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update flow type',
33+
error_code: :invalid_flow_type,
34+
details: db_flow_type.errors)
2535
end
2636

2737
UpdateRuntimeCompatibilityJob.perform_later({ runtime_id: current_runtime.id })
@@ -49,6 +59,7 @@ def update_flowtype(flow_type, t)
4959
db_object.aliases = update_translations(flow_type.alias, db_object.aliases)
5060
db_object.version = "#{flow_type.version.major}.#{flow_type.version.minor}.#{flow_type.version.patch}"
5161
db_object.save
62+
db_object
5263
end
5364

5465
def find_datatype(identifier, t)

app/services/runtimes/runtime_function_definitions/update_service.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Runtimes
44
module RuntimeFunctionDefinitions
55
class UpdateService
66
include Sagittarius::Database::Transactional
7+
include Code0::ZeroTrack::Loggable
78

89
attr_reader :current_runtime, :runtime_function_definitions
910

@@ -19,14 +20,22 @@ def execute
1920
# rubocop:enable Rails/SkipsModelValidations
2021
runtime_function_definitions.each do |runtime_function_definition|
2122
response = update_runtime_function_definition(runtime_function_definition, t)
22-
unless response.persisted?
23-
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update runtime function definition',
24-
payload: response.errors)
25-
end
23+
next if response.persisted?
24+
25+
logger.error(message: 'Failed to update runtime function definition',
26+
runtime_id: current_runtime.id,
27+
definition_identifier: runtime_function_definition.identifier,
28+
errors: response.errors.full_messages)
29+
30+
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update runtime function definition',
31+
error_code: :invalid_runtime_function_definition,
32+
details: response.errors)
2633
end
2734

2835
UpdateRuntimeCompatibilityJob.perform_later({ runtime_id: current_runtime.id })
2936

37+
logger.info(message: 'Updated runtime function definitions for runtime', runtime_id: current_runtime.id)
38+
3039
ServiceResponse.success(message: 'Updated runtime function definition', payload: runtime_function_definitions)
3140
end
3241
end

docs/graphql/enum/errorcodeenum.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Represents the available error responses
2828
| `INVALID_EXTERNAL_IDENTITY` | This external identity is invalid |
2929
| `INVALID_FLOW` | The flow is invalid because of active model errors |
3030
| `INVALID_FLOW_SETTING` | The flow setting is invalid because of active model errors |
31+
| `INVALID_FLOW_TYPE` | The flow type is invalid because of active model errors |
3132
| `INVALID_GENERIC_MAPPER` | The generic mapper is invalid because of active model errors |
3233
| `INVALID_LOGIN_DATA` | Invalid login data provided |
3334
| `INVALID_NAMESPACE_LICENSE` | The namespace license is invalid because of active model errors |

0 commit comments

Comments
 (0)