forest_liana 9.6.0 → 9.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdddfd71dbc4f9c5ddab069162d5b0ba65c057c6f9e25cda811259e72e1daaa8
4
- data.tar.gz: 8213f378007db1ac2663b3143c0e8cc5ca35a63e603c8fb81b2c4bdbbcb7d270
3
+ metadata.gz: 654d11ad9ebc49989ce8f011c901cd93a8ec42d524242e4fb81a28c6ddf82028
4
+ data.tar.gz: 653d6d504a67d2bfbd34a73bbe4d091a8f076f3eaf72161da83cd72f0ce0dd23
5
5
  SHA512:
6
- metadata.gz: 1f805f7d8604f9db01bb69a41d6a70d0b30d1baa4897e12cf4d16d2805c915d272cf197111d8102c7d1f543efbd34490399d8d86144840c615b1a02a2cc03e36
7
- data.tar.gz: 257e946211ad7b126c99ef5f75e45f2f5e8e073b9c4996294ac1d3fcce1da7fbaa4db06d52284ead53072b3c7585d72a4cc1d7b2a7a3a61f5dfe0c37325c7ca6
6
+ metadata.gz: ecfe2712fe3abab2c261ee042b40964747d7d8f1b7289538e4fe1072f4f999bae6c2cbc7b3c165e3b170d7fd548e5041d85d29f10f9eb9ec04262ed6cf9383cc
7
+ data.tar.gz: 21589dd2b1f38b9d12d32fd92b41af0f449dad28b3139ca6692fe6729482eb0a16474dd83763c0702902c5a2c4514f6b33c4fee201442199688a8f7302dfe136
@@ -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
 
@@ -9,8 +9,10 @@ module ForestLiana
9
9
  headers: base_headers.merge(headers),
10
10
  query: query,
11
11
  }).response
12
- rescue
13
- raise "Cannot reach Forest API at #{forest_api_url}#{route}, it seems to be down right now."
12
+ rescue => error
13
+ FOREST_LOGGER.error "Cannot reach Forest API at #{forest_api_url}#{route}, it seems to be down right now."
14
+ FOREST_REPORTER.report error
15
+ raise error
14
16
  end
15
17
  end
16
18
 
@@ -28,8 +30,10 @@ module ForestLiana
28
30
  query: query,
29
31
  body: body.to_json,
30
32
  }).response
31
- rescue
32
- raise "Cannot reach Forest API at #{post_route}, it seems to be down right now."
33
+ rescue => error
34
+ FOREST_LOGGER.error "Cannot reach Forest API at #{post_route}, it seems to be down right now."
35
+ FOREST_REPORTER.report error
36
+ raise error
33
37
  end
34
38
  end
35
39
 
@@ -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.4"
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.4
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-27 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