forest_liana 9.6.0 → 9.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdddfd71dbc4f9c5ddab069162d5b0ba65c057c6f9e25cda811259e72e1daaa8
4
- data.tar.gz: 8213f378007db1ac2663b3143c0e8cc5ca35a63e603c8fb81b2c4bdbbcb7d270
3
+ metadata.gz: 4ba2b1f8d8557f9d5627817377b70bb733804ab8cba4f8f5c63868261f9e00ad
4
+ data.tar.gz: 8d493de4d0148d02e826338b6bb2287c1015094333dfe9891de39be17cc7de8b
5
5
  SHA512:
6
- metadata.gz: 1f805f7d8604f9db01bb69a41d6a70d0b30d1baa4897e12cf4d16d2805c915d272cf197111d8102c7d1f543efbd34490399d8d86144840c615b1a02a2cc03e36
7
- data.tar.gz: 257e946211ad7b126c99ef5f75e45f2f5e8e073b9c4996294ac1d3fcce1da7fbaa4db06d52284ead53072b3c7585d72a4cc1d7b2a7a3a61f5dfe0c37325c7ca6
6
+ metadata.gz: 1e136b9bfe6ba3bb94a5c525f04c6db27a88989fa8b2bff0b2a4341266b8ae901c5cac8c53111d4d0e1b443a9b4dfffdb5954f40a72ac31d1a62ff89a8f2a83b
7
+ data.tar.gz: a8e80f6812a1146af8f3faaa5c20733d3cb731f9a0cd79e63bf93118daa1daadb4e6e5e18d5ae6c54d8f09c4bb567b953af474e63b29ffac365c89424c8fcc92
@@ -127,8 +127,8 @@ module ForestLiana
127
127
  ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/relationships/#{attribute_name}"
128
128
  end
129
129
  end
130
- rescue TypeError, ActiveRecord::StatementInvalid, NoMethodError
131
- puts "Cannot load the association #{attribute_name} on #{object.class.name} #{object.id}."
130
+ rescue TypeError, ActiveRecord::StatementInvalid, NoMethodError => exception
131
+ FOREST_LOGGER.warn "Cannot load the association #{attribute_name} on #{object.class.name} #{object.id}.\n#{exception&.backtrace&.join("\n\t")}"
132
132
  end
133
133
  end
134
134
 
@@ -2,12 +2,13 @@ module ForestLiana
2
2
  module Ability
3
3
  module Exceptions
4
4
  class AccessDenied < ForestLiana::Errors::ExpectedError
5
- def initialize
5
+ def initialize (backtrace = nil)
6
6
  super(
7
7
  403,
8
8
  :forbidden,
9
9
  'You don\'t have permission to access this resource',
10
- 'AccessDenied'
10
+ 'AccessDenied',
11
+ backtrace
11
12
  )
12
13
  end
13
14
  end
@@ -2,12 +2,13 @@ module ForestLiana
2
2
  module Ability
3
3
  module Exceptions
4
4
  class ActionConditionError < ForestLiana::Errors::ExpectedError
5
- def initialize
5
+ def initialize (backtrace = nil)
6
6
  super(
7
7
  409,
8
8
  :conflict,
9
9
  'The conditions to trigger this action cannot be verified. Please contact an administrator.',
10
- 'InvalidActionConditionError'
10
+ 'InvalidActionConditionError',
11
+ backtrace
11
12
  )
12
13
  end
13
14
  end
@@ -3,13 +3,14 @@ module ForestLiana
3
3
  module Exceptions
4
4
  class RequireApproval < ForestLiana::Errors::ExpectedError
5
5
  attr_reader :data
6
- def initialize(data)
6
+ def initialize(data, backtrace = nil)
7
7
  @data = data
8
8
  super(
9
9
  403,
10
10
  :forbidden,
11
11
  'This action requires to be approved.',
12
12
  'CustomActionRequiresApprovalError',
13
+ backtrace,
13
14
  )
14
15
  end
15
16
  end
@@ -2,12 +2,13 @@ module ForestLiana
2
2
  module Ability
3
3
  module Exceptions
4
4
  class TriggerForbidden < ForestLiana::Errors::ExpectedError
5
- def initialize
5
+ def initialize(backtrace = nil)
6
6
  super(
7
7
  403,
8
8
  :forbidden,
9
9
  'You don\'t have the permission to trigger this action',
10
- 'CustomActionTriggerForbiddenError'
10
+ 'CustomActionTriggerForbiddenError',
11
+ backtrace,
11
12
  )
12
13
  end
13
14
  end
@@ -2,12 +2,13 @@ module ForestLiana
2
2
  module Ability
3
3
  module Exceptions
4
4
  class UnknownCollection < ForestLiana::Errors::ExpectedError
5
- def initialize(collection_name)
5
+ def initialize(collection_name, backtrace = nil)
6
6
  super(
7
7
  409,
8
8
  :conflict,
9
9
  "The collection #{collection_name} doesn't exist",
10
- 'collection not found'
10
+ 'collection not found',
11
+ backtrace
11
12
  )
12
13
  end
13
14
  end
@@ -65,8 +65,8 @@ module ForestLiana
65
65
  end
66
66
 
67
67
  records.select(@collection.table_name + '.id').count == attributes[:ids].count
68
- rescue
69
- raise ForestLiana::Ability::Exceptions::ActionConditionError.new
68
+ rescue => exception
69
+ raise ForestLiana::Ability::Exceptions::ActionConditionError.new(exception.backtrace)
70
70
  end
71
71
  end
72
72
 
@@ -27,8 +27,8 @@ module ForestLiana
27
27
  is_allowed
28
28
  rescue ForestLiana::Errors::ExpectedError => exception
29
29
  raise exception
30
- rescue
31
- raise ForestLiana::Ability::Exceptions::UnknownCollection.new(collection_name)
30
+ rescue => exception
31
+ raise ForestLiana::Ability::Exceptions::UnknownCollection.new(collection_name, exception.backtrace)
32
32
  end
33
33
  end
34
34
 
@@ -45,8 +45,8 @@ module ForestLiana
45
45
  smart_action_approval.can_execute?
46
46
  rescue ForestLiana::Errors::ExpectedError => exception
47
47
  raise exception
48
- rescue
49
- raise ForestLiana::Ability::Exceptions::UnknownCollection.new(collection_name)
48
+ rescue => exception
49
+ raise ForestLiana::Ability::Exceptions::UnknownCollection.new(collection_name, exception.backtrace)
50
50
  end
51
51
  end
52
52
 
@@ -10,7 +10,10 @@ module ForestLiana
10
10
  query: query,
11
11
  }).response
12
12
  rescue
13
- raise "Cannot reach Forest API at #{forest_api_url}#{route}, it seems to be down right now."
13
+ message = "Cannot reach Forest API at #{forest_api_url}#{route}, it seems to be down right now."
14
+ FOREST_LOGGER.error message
15
+ FOREST_REPORTER.report message
16
+ raise
14
17
  end
15
18
  end
16
19
 
@@ -29,7 +32,10 @@ module ForestLiana
29
32
  body: body.to_json,
30
33
  }).response
31
34
  rescue
32
- raise "Cannot reach Forest API at #{post_route}, it seems to be down right now."
35
+ message = "Cannot reach Forest API at #{post_route}, it seems to be down right now."
36
+ FOREST_LOGGER.error message
37
+ FOREST_REPORTER.report message
38
+ raise
33
39
  end
34
40
  end
35
41
 
@@ -44,11 +44,13 @@ module ForestLiana
44
44
  class ExpectedError < StandardError
45
45
  attr_reader :error_code, :status, :message, :name
46
46
 
47
- def initialize(error_code, status, message, name = nil)
47
+ def initialize(error_code, status, message, name = nil, backtrace = nil)
48
48
  @error_code = error_code
49
49
  @status = status
50
50
  @message = message
51
51
  @name = name
52
+
53
+ set_backtrace(backtrace) unless backtrace.nil?
52
54
  end
53
55
 
54
56
  def display_error
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "9.6.0"
2
+ VERSION = "9.6.3"
3
3
  end
@@ -0,0 +1,34 @@
1
+ module ForestLiana
2
+ describe Errors do
3
+ describe 'ExpectedError' do
4
+ describe 'when initializing' do
5
+ describe 'when backtrace is added' do
6
+ it 'should add the backtrace to the errors if passed' do
7
+ err = nil
8
+
9
+ begin
10
+ raise "This is an exception"
11
+ rescue => error
12
+ err = ForestLiana::Errors::ExpectedError.new(300, 300, error.message, nil, error.backtrace )
13
+ end
14
+
15
+ expect(err.backtrace).to be_truthy
16
+ end
17
+ end
18
+ describe 'when backtrace is not added' do
19
+ it 'should not break nor add any backtrace' do
20
+ err = nil
21
+
22
+ begin
23
+ raise "This is an exception"
24
+ rescue => error
25
+ err = ForestLiana::Errors::ExpectedError.new(300, 300, error.message, nil)
26
+ end
27
+
28
+ expect(err.backtrace).to be_falsy
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,44 @@
1
+ module ForestLiana
2
+ describe ForestApiRequester do
3
+ describe 'when an error occurs' do
4
+ before do
5
+ allow(HTTParty).to receive(:get).and_raise(StandardError, 'Custom error message')
6
+ allow(HTTParty).to receive(:post).and_raise(StandardError, 'Custom error message')
7
+ end
8
+
9
+ describe 'Get' do
10
+ it 'should keep the original error and raise it with backtrace' do
11
+ err = nil
12
+
13
+ begin
14
+ ForestApiRequester.get('/incorrect_url')
15
+ rescue => error
16
+ err = error
17
+ end
18
+
19
+ expect(error)
20
+ .to be_instance_of(StandardError)
21
+ .and have_attributes(:message => 'Custom error message')
22
+ .and have_attributes(:backtrace => be_truthy)
23
+ end
24
+ end
25
+
26
+ describe 'Post' do
27
+ it 'should keep the original error and raise it with backtrace' do
28
+ err = nil
29
+
30
+ begin
31
+ ForestApiRequester.post('/incorrect_url')
32
+ rescue => error
33
+ err = error
34
+ end
35
+
36
+ expect(error)
37
+ .to be_instance_of(StandardError)
38
+ .and have_attributes(:message => 'Custom error message')
39
+ .and have_attributes(:backtrace => be_truthy)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.6.0
4
+ version: 9.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-10 00:00:00.000000000 Z
11
+ date: 2024-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -329,6 +329,7 @@ files:
329
329
  - lib/tasks/clear_oidc_data.rake
330
330
  - lib/tasks/display_apimap.rake
331
331
  - lib/tasks/send_apimap.rake
332
+ - spec/config/initializers/errors_spec.rb
332
333
  - spec/config/initializers/logger_spec.rb
333
334
  - spec/dummy/README.rdoc
334
335
  - spec/dummy/Rakefile
@@ -420,6 +421,7 @@ files:
420
421
  - spec/services/forest_liana/ability/permission_spec.rb
421
422
  - spec/services/forest_liana/apimap_sorter_spec.rb
422
423
  - spec/services/forest_liana/filters_parser_spec.rb
424
+ - spec/services/forest_liana/forest_api_requester_spec.rb
423
425
  - spec/services/forest_liana/has_many_getter_spec.rb
424
426
  - spec/services/forest_liana/ip_whitelist_checker_spec.rb
425
427
  - spec/services/forest_liana/line_stat_getter_spec.rb
@@ -632,6 +634,7 @@ test_files:
632
634
  - test/services/forest_liana/operator_date_interval_parser_test.rb
633
635
  - test/services/forest_liana/schema_adapter_test.rb
634
636
  - test/test_helper.rb
637
+ - spec/config/initializers/errors_spec.rb
635
638
  - spec/config/initializers/logger_spec.rb
636
639
  - spec/dummy/README.rdoc
637
640
  - spec/dummy/Rakefile
@@ -723,6 +726,7 @@ test_files:
723
726
  - spec/services/forest_liana/ability/permission_spec.rb
724
727
  - spec/services/forest_liana/apimap_sorter_spec.rb
725
728
  - spec/services/forest_liana/filters_parser_spec.rb
729
+ - spec/services/forest_liana/forest_api_requester_spec.rb
726
730
  - spec/services/forest_liana/has_many_getter_spec.rb
727
731
  - spec/services/forest_liana/ip_whitelist_checker_spec.rb
728
732
  - spec/services/forest_liana/line_stat_getter_spec.rb