{"record":{"id":"b7cd01f010c0f4da","repo":"we-promise/sure","slug":"invalid-response","errorCode":"invalid_response","errorMessage":"Invalid response from Brex API","messagePattern":"Invalid response from Brex API","errorType":"exception","errorClass":"Provider::Brex::BrexError","httpStatus":null,"severity":"error","filePath":"app/models/provider/brex.rb","lineNumber":179,"sourceCode":"\n    def get_json(path, params: {})\n      query = params.present? ? \"?#{URI.encode_www_form(params)}\" : \"\"\n      request_path = \"#{path}#{query}\"\n\n      response = self.class.get(\n        \"#{base_url}#{request_path}\",\n        headers: auth_headers\n      )\n\n      handle_response(response, path: path)\n    rescue BrexError\n      raise\n    rescue SocketError, Net::OpenTimeout, Net::ReadTimeout => e\n      Rails.logger.error \"Brex API: GET #{path} failed: #{e.class}: #{e.message}\"\n      raise BrexError.new(\"Exception during GET request: #{e.message}\", :request_failed)\n    rescue JSON::ParserError => e\n      Rails.logger.error \"Brex API: invalid JSON for GET #{path}: #{e.message}\"\n      raise BrexError.new(\"Invalid response from Brex API\", :invalid_response)\n    rescue => e\n      Rails.logger.error \"Brex API: Unexpected error during GET #{path}: #{e.class}: #{e.message}\"\n      raise BrexError.new(\"Exception during GET request: #{e.message}\", :request_failed)\n    end\n\n    def extract_records(response_payload)\n      return response_payload if response_payload.is_a?(Array)\n\n      payload = response_payload.with_indifferent_access\n      payload[:items] ||\n        payload[:data] ||\n        payload[:accounts] ||\n        payload[:transactions] ||\n        []\n    end\n\n    def auth_headers\n      {","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/provider/brex.rb#L161-L197","documentation":"SureImport::NotPublishableError raised by SureImport#publish_later (code: not_publishable) when publishable? is false. publishable? requires the upload to be configured (uploaded?) AND dry_run.values.sum to be positive — i.e., the dry-run parse produced at least one record that would be created. So the file uploaded fine but contained zero publishable rows (all rows invalid/empty/unparseable, or dry_run never ran). The guard fires before status flips to :importing and before ImportJob is enqueued.","triggerScenarios":"Calling publish_later after an upload whose dry-run stats sum to zero — every row failed validation, the file had headers only, column mapping mismatched so nothing parsed, or the file was empty; also calling publish before dry_run results exist.","commonSituations":"CSV uploads with wrong delimiter/locale formats that parse to zero rows; template mismatch after a schema change; users uploading an Excel export with a preamble row breaking the parser; double-clicking publish on a file whose validation quietly removed all rows.","solutions":["Inspect sure_import.dry_run to see per-type counts and which validation stage zeroed them out","Fix the source file/delimiter/headers or the column mapping and re-upload so dry_run yields rows","Only expose the publish action in the UI when publishable? is true","If all rows are invalid-by-design (e.g., duplicates to skip), confirm whether that should be a no-op success instead of an error"],"exampleFix":"# before\nimport.publish_later\n\n# after\nunless import.publishable?\n  Rails.logger.info(\"SureImport #{import.id} not publishable: dry_run=#{import.dry_run.inspect}\")\n  return redirect_to import, alert: \"No publishable records — check row errors\"\nend\nimport.publish_later","handlingStrategy":"validation","validationCode":"import.reload\nunless import.publishable?\n  Rails.logger.info(\"dry_run stats: #{import.dry_run.inspect}\")\n  return redirect_to import, alert: \"Upload has no publishable records — fix rows and re-upload\"\nend","typeGuard":null,"tryCatchPattern":"begin\n  import.publish_later\nrescue SureImport::NotPublishableError\n  redirect_to import, alert: \"No publishable records found in this import\"\nend","preventionTips":["Run and inspect dry_run results after upload; show row-level error counts to users","Only enable the publish action when import.publishable? is true","Validate file format/headers at upload time so zero-row parses surface early","Cover the empty-import case in tests alongside MaxRowCountExceededError"],"tags":["sure-import","csv-import","dry-run","validation","publish"],"backgroundTag":"import-no-valid-rows","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}