fablabbcn / smartcitizen-api

The Smart Citizen Engine
https://developer.smartcitizen.me
GNU Affero General Public License v3.0
10 stars 4 forks source link

TypeError: can't convert String into an exact number #320

Closed sentry-io[bot] closed 1 week ago

sentry-io[bot] commented 2 months ago

Sentry Issue: SC-API-HX

ArgumentError: argument out of range
  app/models/kairos.rb:79:in `query'
    data['end_absolute'] = Time.parse(params[:to]).to_i * 1000
  app/controllers/v0/readings_controller.rb:12:in `index'
    render json: Kairos.query(params)
...
(78 additional frame(s) were not displayed)

TypeError: can't convert String into an exact number
  app/models/kairos.rb:81:in `rescue in query'
    data['end_absolute'] = Time.at(params[:to])
  app/models/kairos.rb:78:in `query'
    begin
  app/controllers/v0/readings_controller.rb:12:in `index'
    render json: Kairos.query(params)
...
(78 additional frame(s) were not displayed)
oscgonfer commented 2 months ago

Hi there, I think this is an easy one ( :crossed_fingers: ) After a quick testing on the api, I think this comes from an unhandled case when the timestamps are truncated or not valid on either, the from or the to parameter in the devices/<id>/readings/ endpoint.

Logs from the app:

smartcitizen-api-app-1  | I, [2024-04-29T14:43:11.762034 #1]  INFO -- : [31.221.250.145] [5dc666f7-b30c-4ea6-91d6-088b662d6331] Completed 500 Internal Server Error in 37ms (ActiveRecord: 10.7ms | Allocations: 11674)
smartcitizen-api-app-1  | F, [2024-04-29T14:43:11.762577 #1] FATAL -- : [31.221.250.145] [5dc666f7-b30c-4ea6-91d6-088b662d6331]   
smartcitizen-api-app-1  | [31.221.250.145] [5dc666f7-b30c-4ea6-91d6-088b662d6331] TypeError (can't convert String into an exact number):
smartcitizen-api-app-1  | [31.221.250.145] [5dc666f7-b30c-4ea6-91d6-088b662d6331]   
smartcitizen-api-app-1  | [31.221.250.145] [5dc666f7-b30c-4ea6-91d6-088b662d6331] app/models/kairos.rb:81:in `rescue in query'
smartcitizen-api-app-1  | [31.221.250.145] [5dc666f7-b30c-4ea6-91d6-088b662d6331] app/models/kairos.rb:78:in `query'
smartcitizen-api-app-1  | [31.221.250.145] [5dc666f7-b30c-4ea6-91d6-088b662d6331] app/controllers/v0/readings_controller.rb:12:in `index'
smartcitizen-api-app-1  | I, [2024-04-29T14:43:11.772487 #1]  INFO -- : [31.221.250.145] [5dc666f7-b30c-4ea6-91d6-088b662d6331] Processing by V0::ErrorsController#exception as JSON
smartcitizen-api-app-1  | I, [2024-04-29T14:43:11.778108 #1]  INFO -- sentry: [Transport] Sending envelope with items [event] e61cffd8377c4989965ce816d57a300d to Sentry
smartcitizen-api-app-1  | I, [2024-04-29T14:43:11.778182 #1]  INFO -- : [31.221.250.145] [5dc666f7-b30c-4ea6-91d6-088b662d6331]   Parameters: {"sensor_id"=>"113", "rollup"=>"1m", "from"=>"2020-01-01", "to"=>"2020-0", "id"=>"16869"}
smartcitizen-api-app-1  | I, [2024-04-29T14:43:11.779236 #1]  INFO -- : [31.221.250.145] [5dc666f7-b30c-4ea6-91d6-088b662d6331] Completed 500 Internal Server Error in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms | Allocations: 148)
smartcitizen-api-app-1  | I, [2024-04-29T14:43:11.779802 #1]  INFO -- : source=rack-timeout id=77f558ff-f41a-4e21-abb3-e5689ac40718 timeout=20000ms service=59ms state=completed
timcowlishaw commented 2 weeks ago

Addressed in #330